I am using an ItemsControl
which has a list of Objects... inside the ItemContainerTemplate
I have another DataTemplate
. Inside of that DataTemplate
I can't bind to the ItemsControl.ItemSource
anymore.
Since I am not very good with bindings via Find Ancestor
and RelativeSource
etc. I tried everything without even knowing how to properly use them...
<ItemsControl ItemsSource="{Binding NoteList}">
<ItemsControl.ItemTemplate>
<ItemContainerTemplate>
<GroupBox Header="{Binding Title}"
Name="MyNoteList"
Style="{DynamicResource MaterialDesignCardGroupBox}"
Margin="16">
<GroupBox.HeaderTemplate>
<DataTemplate>
<DockPanel>
<TextBlock Margin="8,0,0,0"
VerticalAlignment="Center"
Style="{StaticResource MaterialDesignSubheadingTextBlock}"
Text="{Binding}" />
<Button Padding="5"
Command="{Binding DataContext.DeleteCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ItemsControl}}, Path=DataContext.NoteId}"
HorizontalAlignment="Right"
Background="Transparent"
BorderBrush="Transparent">
<materialDesign:PackIcon Kind="Delete"
Height="25"
Width="25"
VerticalAlignment="Center" />
</Button>
</DockPanel>
</DataTemplate>
</GroupBox.HeaderTemplate>
</GroupBox>
</ItemContainerTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
I like to mention, that I want to bind to an object from NoteList
with the name NoteId
inside the CommandParameter
. But I keep getting "null" from it. The binding inside my ViewModel is definitely correct. So i only need to know, how to access the NoteId
Property from my NoteList