stackpanel

时间:2017-12-14 14:24:07

标签: c# xml wpf windows xaml

我不明白为什么我(生成的)XAML代码的对齐是错误的。

XAML:

<ScrollViewer>
        <StackPanel Orientation="Vertical">

            <HeaderedContentControl Header="innerer Ex-Schutz Anforderung">
                <Grid HorizontalAlignment="Stretch">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="5"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="5"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="5"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="5"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="5"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>

                    <Grid HorizontalAlignment="Stretch" Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="3">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="48"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>

                        <Rectangle Grid.Column="0" Margin="0,0,2,0" Stretch="Fill" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" StrokeThickness="0" Stroke="Transparent" Fill ="#FFFFFF88"/>
                        <TextBlock Margin="5" Grid.Column="0" Text="IX02"/>
                        <TextBlock Grid.Column="1" VerticalAlignment="Center" Margin="0,0,5,0" Text="Ex-Zone"/>
                        <mvvmui:VmpEditor Grid.Column="2" DataContext="{Binding Data[This][]}" ShowCaption="False" WrapReadOnlyText="True"/>
                    </Grid>

                    <Grid HorizontalAlignment="Stretch" Grid.Row="0" Grid.Column="5" Grid.ColumnSpan="3">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="48"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>

                        <Rectangle Grid.Column="0" Margin="0,0,2,0" Stretch="Fill" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" StrokeThickness="0" Stroke="Transparent" Fill ="#FFFFFF88"/>
                        <TextBlock Margin="5" Grid.Column="0" Text="IX04"/>
                        <TextBlock Grid.Column="1" VerticalAlignment="Center" Margin="0,0,5,0" Text="Ex-Gruppe"/>
                        <mvvmui:VmpEditor Grid.Column="2" DataContext="{Binding Data[This][0173-1---ADVANCED_1_1#01-ADN507#007/0173-1#01-ADR534#007/0173-1#02-AAR158#007/0173-1#02-AAR159#005/0173-1#02-AAQ920#005/0173-1#02-AAO370#004]}" ShowCaption="False" WrapReadOnlyText="True"/>
                    </Grid>

                    <Grid HorizontalAlignment="Stretch" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="48"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>

                        <Rectangle Grid.Column="0" Margin="0,0,2,0" Stretch="Fill" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" StrokeThickness="0" Stroke="Transparent" Fill ="#FFFFFF88"/>
                        <TextBlock Margin="5" Grid.Column="0" Text="IX06"/>
                        <TextBlock Grid.Column="1" VerticalAlignment="Center" Margin="0,0,5,0" Text="Temp.klasse"/>
                        <mvvmui:VmpEditor Grid.Column="2" DataContext="{Binding Data[This][0173-1---ADVANCED_1_1#01-ADN507#007/0173-1#01-ADR534#007/0173-1#02-AAR158#007/0173-1#02-AAR159#005/0173-1#02-AAQ920#005/0173-1#02-AAO371#004]}" ShowCaption="False" WrapReadOnlyText="True"/>
                    </Grid>
                </Grid>
            </HeaderedContentControl>

            <HeaderedContentControl Header="äußerer Ex-Schutz Anforderung">
                <Grid HorizontalAlignment="Stretch">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="5"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="5"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="5"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="5"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="5"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>

                    <Grid HorizontalAlignment="Stretch" Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="3">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="48"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>

                        <Rectangle Grid.Column="0" Margin="0,0,2,0" Stretch="Fill" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" StrokeThickness="0" Stroke="Transparent" Fill ="#FFFFFF88"/>
                        <TextBlock Margin="5" Grid.Column="0" Text="AX02"/>
                        <TextBlock Grid.Column="1" VerticalAlignment="Center" Margin="0,0,5,0" Text="Ex-Zone Umgebung"/>
                        <mvvmui:VmpEditor Grid.Column="2" DataContext="{Binding Data[CboProcessConnection].PropertyList[EPROutsideZone]}" ShowCaption="False" WrapReadOnlyText="True"/>
                    </Grid>

                    <Grid HorizontalAlignment="Stretch" Grid.Row="0" Grid.Column="5" Grid.ColumnSpan="3">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="48"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>

                        <Rectangle Grid.Column="0" Margin="0,0,2,0" Stretch="Fill" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" StrokeThickness="0" Stroke="Transparent" Fill ="#FFFFFF88"/>
                        <TextBlock Margin="5" Grid.Column="0" Text="AX04"/>
                        <TextBlock Grid.Column="1" VerticalAlignment="Center" Margin="0,0,5,0" Text="Ex-Gruppe Umgebung"/>
                        <mvvmui:VmpEditor Grid.Column="2" DataContext="{Binding Data[CboProcessConnection].PropertyList[EPROutsideGroup]}" ShowCaption="False" WrapReadOnlyText="True"/>
                    </Grid>

                    <Grid HorizontalAlignment="Stretch" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="48"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>

                        <Rectangle Grid.Column="0" Margin="0,0,2,0" Stretch="Fill" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" StrokeThickness="0" Stroke="Transparent" Fill ="#FFFFFF88"/>
                        <TextBlock Margin="5" Grid.Column="0" Text="AX06"/>
                        <TextBlock Grid.Column="1" VerticalAlignment="Center" Margin="0,0,5,0" Text="Temperaturklasse Umgebung"/>
                        <mvvmui:VmpEditor Grid.Column="2" DataContext="{Binding Data[CboProcessConnection].PropertyList[EPROutsideTempClass]}" ShowCaption="False" WrapReadOnlyText="True"/>
                    </Grid>
                </Grid>
            </HeaderedContentControl>
        </StackPanel>
    </ScrollViewer>

在这里你可以得到结果:

enter image description here

它不容易看到,但右侧的两个黄色框应完全在彼此之下。但是较低的是右边的几个像素。

有人理解吗?

有趣的是,当您向StackPanel(例如1500)输入固定宽度时,它可以正常工作。但我不想要一个固定的宽度。

1 个答案:

答案 0 :(得分:1)

您在单独的网格中有自动宽度列。如果您希望两个不同网格中的列具有相同的宽度,则有三个选项:

  1. 固定尺寸​​。那是蹩脚的,你不想要它。
  2. 把所有东西放在一个大格子里。
  3. Grid.IsSharedSizeScope=“True”放在两个网格的某个公共父元素上,并在自动调整的列上添加SharedSizeGroup=“SomeArbitaryName”,这些列在两个不同的子网格中的大小略有不同,并且将第三列的位置设置为不同结果(这是每个中的第一列)。我相信这是你个案中最好的解决方案。