Accessing ItemsControl Items in C# (Unity)
Hi there,
I need to iterate through the Items of an ItemsControl in C# (as UIElements, like Panel Children).
All of the examples I have found for WPF use a variation of this code:
But ItemContainerGenerator.ContainerFromIndex does not exist in the Noesis ItemsControl class.
What is the best way of doing this in Noesis?
Thanks,
Mark
I need to iterate through the Items of an ItemsControl in C# (as UIElements, like Panel Children).
All of the examples I have found for WPF use a variation of this code:
Code: Select all
for(int i = 0; i < itemsControl.Items.Count; i++)
{
UIElement uiElement = (UIElement)itemsControl.ItemContainerGenerator.ContainerFromIndex(i);
}
What is the best way of doing this in Noesis?
Thanks,
Mark
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: Accessing ItemsControl Items in C# (Unity)
Hi,
We are working to implement ItemContainerGenerator for next version.
Meanwhile, the solution is to provide access to the Panel that holds the item containers. You will need to name the ItemsPresenter or directly define and name the Panel you want to use as ItemsHost in the control template:
We are working to implement ItemContainerGenerator for next version.
Meanwhile, the solution is to provide access to the Panel that holds the item containers. You will need to name the ItemsPresenter or directly define and name the Panel you want to use as ItemsHost in the control template:
Code: Select all
<ControlTemplate x:Key="CustomItemsControlTemplate" TargetType="ItemsControl">
<Border Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}">
<StackPanel x:Name="itemsPanel" IsItemsHost="True"/>
</Border>
</ControlTemplate> Code: Select all
void IterateItemsControl(ItemsControl itemsControl)
{
StackPanel panel = (StackPanel)itemsControl.GetTemplatChild("itemsPanel");
for(int i = 0; i < itemsControl.Items.Count; i++)
{
UIElement container = (UIElement)panel.Children[i];
}
} Re: Accessing ItemsControl Items in C# (Unity)
Cool, thank you.
Who is online
Users browsing this forum: No registered users and 5 guests