【问题标题】:Last Grid Column Not Auto Resizing With Grid最后一个网格列不使用网格自动调整大小
【发布时间】:2011-06-01 02:28:51
【问题描述】:

我的文本框不是“自动”调整大小时遇到​​问题。我正在尝试创建一个行为和外观类似于 Visual Studio 中的属性编辑器的表单。似乎正在发生的事情是第三列没有扩展以填充网格中所有可用的剩余空间。下图是我的表单在启动时的样子。

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

<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>

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

【问题讨论】:

    标签: wpf


    【解决方案1】:

    再次检查全局设置的任何样式,因为您的布局非常适合我。

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

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

    【讨论】:

    • 感谢您的建议。我已将其归结为示例 SkinnyBlue 主题中 Expander 样式设计中的问题。
    猜你喜欢
    • 1970-01-01
    • 2012-07-03
    • 2012-12-22
    • 1970-01-01
    • 1970-01-01
    • 2011-08-13
    • 2011-01-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多