【问题标题】:WPF StackPanel to make the elements' width to be related each otherWPF StackPanel 使元素的宽度相互关联
【发布时间】:2020-04-09 05:53:45
【问题描述】:

我是 WPF 的新手

在我的代码中,有一个 StackPanel,它有 3 个子控件。

<StackPanel Background="Green" Orientation="Horizontal">
    <TextBlock Width="200">
    <TextBlock Width=???>
    <TextBlock Width="200>
</StackPanel>

第一个和第三个 TextBlocks 已经有了它们的宽度, 但我想让第二个文本块的宽度取决于窗口的大小。 这意味着如果 Window 的宽度为 1000 - 第二个 TextBlock 的宽度应为 600。 可能我应该使用一些 Binding,但我不确定。

感谢您的帮助。 谢谢。

【问题讨论】:

    标签: wpf xaml binding controls stackpanel


    【解决方案1】:

    您应该将StackPanel 替换为Panel,以调整其子项的大小,例如Grid

    <Grid Background="Green">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="200" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="200" />
        </Grid.ColumnDefinitions>
        <TextBlock />
        <TextBlock Grid.Column="1" />
        <TextBlock Grid.Column="2" />
    </Grid>
    

    【讨论】:

      猜你喜欢
      • 2015-11-30
      • 2013-08-14
      • 1970-01-01
      • 2020-03-30
      • 2010-11-08
      • 2015-09-01
      • 2010-11-30
      • 2013-11-08
      • 1970-01-01
      相关资源
      最近更新 更多