简体   繁体   English

网格列和列定义WPF之间的连接

[英]Connection between Grid Column and Column Definition WPF

First of all, I am new to WPF and I am trying to find the proper approach to dynamically resize Column Definitions of a Grid 首先,我是WPF的新手,我正在尝试寻找适当的方法来动态调整网格的列定义大小

  <Grid x:Name="uxFootbarGrid" Height="40" Margin="0" VerticalAlignment="Bottom">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="7*"/>
                        <ColumnDefinition Width="8*"/>
                        <ColumnDefinition Width="105*"/>
                    </Grid.ColumnDefinitions>
                    <Grid x:Name="uxOrderStatusGrid" Margin="0" d:LayoutOverrides="LeftMargin, RightMargin, TopMargin, BottomMargin">
                        <TextBox Margin="0" TextWrapping="Wrap" Text="Status: CMP" VerticalContentAlignment="Center" Background="{x:Null}" BorderThickness="0" Foreground="White" Grid.Column="1"/>
                    </Grid>
                    <Grid Grid.Column="1" Margin="0" d:LayoutOverrides="LeftMargin, RightMargin, TopMargin, BottomMargin">
                        <TextBox x:Name="uxProcessingTextBox" Margin="0" Grid.Column="2" TextWrapping="Wrap" Text="Processing: D" Background="{x:Null}" Foreground="White" VerticalContentAlignment="Center" BorderThickness="0" TextChanged="uxProcessingTextBox_TextChanged"/>
                    </Grid>

                </Grid>

I have Grids inside of Grid. 我在网格内部有网格。 I am trying programatically to find the connection between those. 我正在以编程方式尝试找到这些之间的联系。

The idea is: 这个想法是:

foreach(column in masterGrid)
{
   getAllTextBoxes()
   getTotalWidth()
   setWidthToColumnDefinitionOfMasterGrid()
}

All good at the moment, but I cannot find relation between Control and the Column Definition they belong to. 目前一切都很好,但是我找不到控件和它们所属的列定义之间的关系。

In order to find out which column an element is in, use the Grid class: 为了找出元素所在的列,请使用Grid类:

int columnIndex = Grid.GetColumn(elementName);

In order to access the respective column, access the collection of column definitions on the grid: 为了访问相应的列,请访问网格上的列定义集合:

ColumnDefinition myColumn = uxFootbargrid.ColumnDefinitions[columnIndex];

Once you have the ColumnDefinition, you can go ahead and change the properties you want 一旦有了ColumnDefinition,就可以继续更改所需的属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM