开发者

C# WPF Dynamic UniformGrid

开发者 https://www.devze.com 2023-01-30 12:37 出处:网络
I have a textbox where you can input an integer (which will the size of the UniformGrid). On a button click, a UniformGrid is generated with each grid contains some textblock, textbox, and a button, g

I have a textbox where you can input an integer (which will the size of the UniformGrid). On a button click, a UniformGrid is generated with each grid contains some textblock, textbox, and a button, generated under different ElementName. I went through so many tutorial and all sim开发者_如何学Goply Add something to the children. And I can't seem to set the binding logic worked out - which bind to what, and which is being itemcontrolled. I went through wpftutorial and it just confuses me further. Appreciate if anyone can explain the logic in simple terms.


UniformGrid cannot really be used as an ItemsHost for an ItemsControl, mainly because the DataTemplate can only take a single child, which prohibits its use in this context.

Here's an alternative approach that might help you achieve what you want (I think)

<ListView ItemsSource="{Binding MyData}">
<ListView.View>
  <GridView>
    <GridView.ColumnHeaderContainerStyle>
      <Style TargetType="GridViewColumnHeader">
        <Setter Property="Visibility" Value="Collapsed" />
      </Style>
    </GridView.ColumnHeaderContainerStyle>
    <GridView.Columns>
      <GridViewColumn>
        <GridViewColumn.CellTemplate>
          <DataTemplate>
            <TextBlock Text="{Binding SomeLabelText}" />
          </DataTemplate>
        </GridViewColumn.CellTemplate>
      </GridViewColumn>
      <GridViewColumn>
        <GridViewColumn.CellTemplate>
          <DataTemplate>
            <TextBox Text="{Binding SomeInputText}" />
          </DataTemplate>
        </GridViewColumn.CellTemplate>
      </GridViewColumn>
      <GridViewColumn>
        <GridViewColumn.CellTemplate>
          <DataTemplate>
            <Button Content="{Binding SomeButtonLabel}" />
          </DataTemplate>
        </GridViewColumn.CellTemplate>
      </GridViewColumn>
    </GridView.Columns>
  </GridView>
</ListView.View>

0

精彩评论

暂无评论...
验证码 换一张
取 消