I want to access all the children of ItemControl. Actually, I want to access the button and change its background color.
<ItemsControl x:Name="ItemsControlReminder">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button x:Name="ButtonItemControlParent">
<Grid Height="75">
.....
.....
.....
</Grid>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
My constructor:
public RemindersPage() {
InitializeComponent();
List<Reminder> reminders = new List<Reminder> {........};
ListViewReminder.ItemsSource = reminders;
foreach ( var item in ListViewReminder.Items ) {
UIElement uiElement = (UIElement) ListViewReminder.ItemContainerGenerator.ContainerFromItem(item);
}
}
But it says uielement is null. Also I can't access the button with ui element. How do I access each button and change the background color?