通过C#设置ItemPanelTemplate UniformGrid的行 [英] Setting rows of ItemPanelTemplate UniformGrid through C#

查看:309
本文介绍了通过C#设置ItemPanelTemplate UniformGrid的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我所拥有的:

<ItemsControl x:Name="InfoGrid">
       <!-- ItemsPanelTemplate -->
       <ItemsControl.ItemsPanel>
               <ItemsPanelTemplate>
                     <UniformGrid Rows="4" Columns="5"                                                  Background="LightGray" />
               </ItemsPanelTemplate>
       </ItemsControl.ItemsPanel>
       <!-- ItemTemplate -->
       <ItemsControl.ItemTemplate>
              <DataTemplate>
                   <Border BorderBrush="Black" BorderThickness="{Binding Path=BorderThickness}">
                   <CheckBox Style="{StaticResource styleCustomCheckBox}" IsChecked="{Binding Path=IsChecked, Mode=TwoWay}"/>
                   </Border>
              </DataTemplate>
       </ItemsControl.ItemTemplate>

InfoGrid的itemsource在后面的代码中设置为一个名为infoData的集合,如何通过C#设置此UniformGrid的行/列(最好设置为infoData中未包含的变量)?

The InfoGrid's itemsource is set to a collection called infoData in the code behind, how can I set the Rows/Columns of this UniformGrid through C# (preferably to variables not contained within infoData)?

我尝试了绑定并使用setter,但似乎并没有应用这些值.

I tried binding and using setters but the values don't seem to get applied.

推荐答案

您需要在后面的代码中访问ItemsPanel,以便在运行时设置列.有两个不同的选项,包括浏览VisualTree. 此答案详细描述了选项和步骤.

You'll need to access the ItemsPanel in the code behind in order to set the columns at runtime. There are a couple different options for this, including navigating the VisualTree. This answer describes the options and the steps in good detail.

这篇关于通过C#设置ItemPanelTemplate UniformGrid的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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