最后一个网格列不自动调整网格大小

时间:2010-12-29 14:47:45

标签: wpf

我的TextBoxs有问题而不是“自动”调整大小。我正在尝试创建一个行为和看起来像Visual Studio中的属性编辑器的表单。似乎正在发生的是第三列没有扩展以填充网格中的所有可用剩余空间。下图是我的表单在启动时的外观。

文本框的宽度由第三个ColumnDefinition语句的MinWidth设置决定。此外,宽度设置为“*”。使用任何其他设置时,使用GridSplitter完成的大小调整无法正常工作。

alt text

<StackPanel Orientation="Vertical" VerticalAlignment="Top" x:Name="Stacker" Grid.IsSharedSizeScope="True">
    <Expander x:Name="Expand" IsExpanded="True" Header="This is a test of a Second Panel" Width="{Binding Width, ElementName=Stacker}">
        <Grid x:Name="EditGrid1" Margin="3" >
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"  MinWidth="50" SharedSizeGroup="SharedSize1" />
                <ColumnDefinition Width="Auto" SharedSizeGroup="SharedSize2" />
                <ColumnDefinition Width="*" MinWidth="50" x:Name="ValueCol" />
            </Grid.ColumnDefinitions>
            <GridSplitter Grid.Column="1" x:Name="ToolBoxSplitter1" Grid.Row="1" Grid.RowSpan="6" Panel.ZIndex="1" HorizontalAlignment="Stretch" ResizeBehavior="PreviousAndNext" Width="3"/>

            <TextBlock MaxHeight="40" Grid.Column="0" Grid.Row="1" Text="{x:Static lex:DoSomeThingView.Name}" />
            <TextBlock MaxHeight="40" Grid.Column="0" Grid.Row="2" Text="{x:Static lex:DoSomeThingView.Address}" />
            <TextBlock MaxHeight="40" Grid.Column="0" Grid.Row="3" Text="{x:Static lex:DoSomeThingView.Zip}" />
            <TextBlock MaxHeight="40" Grid.Column="0" Grid.Row="4" Text="{x:Static lex:DoSomeThingView.NumberOfDoors}" TextTrimming="CharacterEllipsis" Grid.IsSharedSizeScope="True" />
            <TextBlock MaxHeight="40" Grid.Column="0" Grid.Row="5" Text="{x:Static lex:DoSomeThingView.DoubleNumber}" />
            <TextBox Grid.Column="2" Grid.Row="1" x:Name="UserName1" MaxHeight="50" TextWrapping="Wrap" 
                     VerticalScrollBarVisibility="Auto"  SpellCheck.IsEnabled="True" />
            <TextBox Grid.Column="2" Grid.Row="2" x:Name="Address1" />
            <TextBox Grid.Column="2" Grid.Row="3" x:Name="Zip1" />
            <TextBox Grid.Column="2" Grid.Row="4" x:Name="NumberOfDoors1" />
            <TextBox Grid.Column="2" Grid.Row="5" x:Name="DoubleNumber1" />
        </Grid>
    </Expander>
</StackPanel>

有关如何纠正此问题的任何建议?

1 个答案:

答案 0 :(得分:0)

再次检查全局设置的任何样式,因为您的布局与我完美配合。

尝试通过本地资源覆盖您的文本框样式

<StackPanel.Resources>
   <Style TargetType="{x:Type TextBox}"/>
</StackPanel.Resources>