Setting rows of ItemPanelTemplate UniformGrid through C#

强颜欢笑 提交于 2019-12-12 02:05:54

问题


Here's what I have:

<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>

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)?

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


回答1:


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.



来源:https://stackoverflow.com/questions/15178726/setting-rows-of-itempaneltemplate-uniformgrid-through-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!