【发布时间】:2021-05-05 14:50:19
【问题描述】:
我使用绑定到 ItemsSource 集合的 ItemsControl,并使用 ItemsWrapGrid 控制面板排列项目。但是 ItemsWrapGrid 面板被放置在 ItemsPanelTemplate 中,所以我无法在 c# 后面的代码中访问该元素。
我尝试使用 VisualTreeHelper 方法在可视化树中找到面板。并且在项目面板模板中使用时不检索元素。
<ItemsControl
x:Name="itemsControl"
ItemTemplate="{TemplateBinding ItemTemplate}"
ItemsSource="{TemplateBinding GalleryItemCollection}"
SelectedItem="{TemplateBinding SelectedItem}">
<itemsControl.ItemsPanel>
<ItemsPanelTemplate>
<ItemsWrapGrid x:Name="itemsWrapGrid"
ItemHeight="{Binding Path=ItemHeight}"
ItemWidth="{Binding Path=ItemWidth}"
MaximumRowsOrColumns="{Binding Path=MaximumColumnCount}"
Orientation="Horizontal" />
</ItemsPanelTemplate>
</itemsControl.ItemsPanel>
</itemsControl>
有人可以帮我如何访问 c# 背后的 itemswrapGrid 代码元素吗?
【问题讨论】:
-
您尝试从何时何地访问
ItemsWrapGrid?
标签: c# uwp itemscontrol itemspaneltemplate winui-3