【问题标题】:WPF: avoid redrawing of groupbox to fit contentWPF:避免重绘组框以适应内容
【发布时间】:2013-11-04 05:04:16
【问题描述】:

我正在使用一个带有 3 行网格的页面,其中每行都包含一个组框。组框还包含具有不同内容的不同网格。 我想让我的所有组框都适合相同的宽度。最初是这样的。但是当第一个组合框的内容从后面的代码更新时,组合框会在很短的时间内重新绘制(宽度更小),但一秒钟后它又适合宽度。 最初是:“未连接”变为“已连接”,因此宽度更小。 我的窗口的宽度设置为最大化,我不想为页面和网格设置固定宽度和高度。有没有办法我只能更新内容,而不让盒子试图适应内容?

示例(2 行):

<Grid Grid.IsSharedSizeScope="True" Name="globalGrid" >
    <Grid.ColumnDefinitions>
        <ColumnDefinition SharedSizeGroup="globalCol"/>          
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition SharedSizeGroup="RowA"/> 
        <RowDefinition SharedSizeGroup="RowA"/>
        <RowDefinition SharedSizeGroup="RowA"/>
    </Grid.RowDefinitions>
    <GroupBox Header="Connection status" 
              Grid.Row="0" Grid.Column="0"
              HorizontalAlignment="Stretch">          
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition />                   
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>             
            <Rectangle Name="Connected"  
                       Style="{StaticResource iconConnectStyle}" 
                       DataContext="{Binding DeviceConnection}" 
                       Grid.Row="0" Grid.Column="0"  />
            <TextBlock Text="device 1:" 
                       Grid.Row="0" Grid.Column="1" 
                       Style="{StaticResource statusText}"/>
            <TextBlock Name="dev1" Grid.Row="0" Grid.Column="2" 
                       Style="{StaticResource statusText}" />                      
        </Grid>
    </GroupBox>

    <GroupBox Header="processing status"  
              Grid.Row="1" Grid.Column="0"
              HorizontalAlignment="Stretch">          
        <StackPanel>
            <TextBlock x:Name="processState" Style="{StaticResource statusText}"/>
            <ProgressBar x:Name="progressState"/>
        </StackPanel>
    </GroupBox>      
</Grid>  

【问题讨论】:

  • 取决于您如何更改内容,但最终结果保持不变,即使对于一小段 GroupBoxes 似乎改变了宽度。至少我是这样理解你的问题的。所以问题是为什么在它起作用的时候要担心这个。 :)
  • 是的,它有效,但并不完美;-)
  • 泰坦尼克号是完美的。我们都知道她发生了什么事。不要担心那些小细节。不要担心这种行为。这在 wpf 中实际上是正常的。

标签: wpf resize width redraw groupbox


【解决方案1】:

我现在正在使用 UniformGrid,它解决了问题...

【讨论】:

    猜你喜欢
    • 2011-01-20
    • 2013-04-15
    • 1970-01-01
    • 2013-03-13
    • 2015-10-07
    • 2020-06-16
    • 2015-03-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多