【问题标题】:Creating RowDefinitions and ColumnDefinitions in code在代码中创建 RowDefinitions 和 ColumnDefinitions
【发布时间】:2012-08-24 19:43:31
【问题描述】:

我为 windows-phone 开发应用程序, 我想创建 2 行 2 列的表 我为此表创建 xaml 代码

<Grid Background="White">   
    <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition/> 
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition /> 
    </Grid.RowDefinitions/>      
</Grid>

我想在代码中创建这个网格

Grid chat_userpicgrid = new Grid();
newgrid.Children.Add(chat_userpicgrid);

但我不知道如何创建 RowDefinitions 和 ColumnDefinitions。

【问题讨论】:

    标签: xaml windows-phone


    【解决方案1】:
    Grid newGrid = new Grid();
    newGrid.Background = new SolidColorBrush(Colors.White);
    newGrid.ColumnDefinitions.Add(new ColumnDefinition());
    newGrid.ColumnDefinitions.Add(new ColumnDefinition());
    newGrid.RowDefinitions.Add(new RowDefinition());
    newGrid.RowDefinitions.Add(new RowDefinition());
    

    在特定单元格中定位元素:

    Grid chat_userpicgrid = new Grid();
    Grid.SetColumn(chat_userpicgrid, 1);
    Grid.SetRow(chat_userpicgrid, 1);
    newGrid.Children.Add(chat_userpicgrid);
    

    看看the code at the bottom of this MSDN page

    【讨论】:

      猜你喜欢
      • 2018-01-22
      • 1970-01-01
      • 1970-01-01
      • 2011-07-31
      • 2022-01-17
      • 2012-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多