网格中的旋转元素 - 打破了分布

时间:2018-04-25 12:47:48

标签: c# wpf xaml

我将网格划分为:

  • 2栏
  • 2行

(0,0) - >元件

(0,1) - >垂直维度

(1,0) - >水平尺寸

横向尺寸正常工作

如何为垂直维度获得相同的效果? 旋转元件会破坏整个系统。我尝试过不同的设置,找不到合适的解决方案。

缩放时,FontSize保持不变也很重要。

一切都在ViewBox中,长度是动态插入的。

<Viewbox Name="MainVB">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="20"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Grid Grid.Column="0" Grid.Row="0" >
                    <StackPanel Orientation="Vertical">
                        <Rectangle Width="{Binding SRW}" Height="20" Margin="0,0,0,0" HorizontalAlignment="Center" StrokeThickness="0" Stroke="Black" Fill="#FFBADCD0"/>
                        <Rectangle Width="{Binding A}" Height="{Binding HF}" Margin="0,0,0,0" HorizontalAlignment="Center" StrokeThickness="0.5" Stroke="Black" Fill="#FF7E7738"/>
                        <Rectangle Width="{Binding A}" Height="{Binding BWR}" Margin="0,-0.5,0,0" HorizontalAlignment="Center" StrokeThickness="0.5" Stroke="Black" Fill="Goldenrod"/>
                    </StackPanel>
                </Grid>

                <Grid Grid.Column="0" Grid.Row="1" >
                    <StackPanel Margin="0,0,0,0" Orientation="Vertical">
                        <TextBlock FontSize="{Binding ElementName=MainVB, Path=ActualWidth, Converter={StaticResource conv}}" Margin="-20,0,0,0" HorizontalAlignment="Center" VerticalAlignment="Top"><Run Text="{Binding A}"/> cm</TextBlock>
                        <Path Width="{Binding A}" Height="10" Margin="20,-5,0,0" StrokeThickness="0.4" Stroke="Black" HorizontalAlignment="Left" VerticalAlignment="Center" Data="M0,5 L100,5 M0,0 L0,10 M100,0 L100,10" Stretch="Fill"/>
                    </StackPanel>
                </Grid>

                <Grid Grid.Column="1" Grid.Row="0" Margin="0,0,0,0" RenderTransformOrigin="0.5,0.5" >
                    <StackPanel Margin="0,0,0,0" Orientation="Vertical" Background="#FFBF8F8F" RenderTransformOrigin="0.5,0.5">
                        <StackPanel.RenderTransform>
                            <TransformGroup>
                                <RotateTransform Angle="270"/>
                            </TransformGroup>
                        </StackPanel.RenderTransform>
                        <TextBlock FontSize="{Binding ElementName=MainVB, Path=ActualWidth, Converter={StaticResource conv}}" Margin="0,0,0,0" HorizontalAlignment="Center" VerticalAlignment="Top"><Run Text="{Binding A}"/> cm</TextBlock>
                        <Path Width="{Binding L}" Height="10" Margin="0,0,0,0" StrokeThickness="0.4" Stroke="Black" Data="M0,5 L100,5 M0,0 L0,10 M100,0 L100,10" Stretch="Fill"/>
                    </StackPanel>
                </Grid>
            </Grid>
        </Viewbox>

Foto

0 个答案:

没有答案