I’ve got problem to define items in my ItemsControls (or in my view or viewModel). May be I don’t know something about mvvm, but here is the question.
I have DataTemplate defined as
<DataTemplate>
<Expander>
<Expander.Header>
<StackPanel>
<TextBlock Margin="2" Text="{Binding Name}" />
<TextBlock>
<Hyperlink>
<Run Text="Delete group" />
</Hyperlink>
</TextBlock>
</StackPanel>
</Expander.Header>
<Expander.Content>
blah-blah-blah
</Expander.Content>
</Expander>
</DataTemplate>
I have a lot of Expanders, each of them have a Hyperlink. And I want the Hyperlink to delete the group – i.e. remove corresponding Expander. I have read about searching on DataTemplate with Visual and Logical – TreeHelper, but it is a bad way to solve my problem – it doesn’t follow mvvm. I know that I need to write a Commmand for the Hyperlink, but how can I retrieve Expander, which I need to delete, and satisfy mvvm – that’s the question.
Any advice, any suggestion…
But, if you are can’t create
staticICommandproperty for some develop reasons, you should useRelativeSourceto find ancestor, which haveDataContextset to ViewModel, which have this command.