WPF 在单独的网格之间共享列宽 [英] WPF share column width between separate grids

查看:16
本文介绍了WPF 在单独的网格之间共享列宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 WPF UserControl 上有以下设置:

<GroupBox><网格>...<网格><Grid.ColumnDefinitions><列定义宽度=自动"/><组框><网格><网格><Grid.ColumnDefinitions><ColumnDefinition 宽度="..."/>

我希望第二个 ColumnDefinition 的宽度与第一个 ColumnDefinition 的宽度相同,但我不想设置明确的宽度.相反,我希望两个网格列都自动拉伸到任一网格列中最长内容的宽度!

这可能吗?

解决方案

可以使用 SharedSizeGroup.另请查看 IsSharedSizeScope.p>

<GroupBox Grid.IsSharedSizeScope="True"><网格>...<网格><Grid.ColumnDefinitions><ColumnDefinition Width="Auto" SharedSizeGroup="A"/><组框><网格><网格><Grid.ColumnDefinitions><ColumnDefinition SharedSizeGroup="A"/>

请参阅此处了解更多信息.p>

I have the following setup on my WPF UserControl:

<GroupBox>
  <Grid>
    ...
    <Grid>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />

<GroupBox>
  <Grid>
    <Grid>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="..." />

I'd like the second ColumnDefinition to be the same width as the first ColumnDefinition, but I don't want to set an explicit width. Instead, I want both grids columns to automatically stretch to the width of the longest piece of content in either grid column!

Is this possible?

解决方案

It is possible by using SharedSizeGroup. Also check out IsSharedSizeScope.

<GroupBox Grid.IsSharedSizeScope="True">
  <Grid>
    ...
    <Grid>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" SharedSizeGroup="A" />

<GroupBox>
  <Grid>
    <Grid>
      <Grid.ColumnDefinitions>
        <ColumnDefinition SharedSizeGroup="A" />

See here for more information.

这篇关于WPF 在单独的网格之间共享列宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆