Answer the question
In order to leave comments, you need to log in
How to set different datacontext properties of one object?
There is a viewmodel MainWindowVM. The view has an itemscontrol bound to the collection.
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Command="{Binding }" CommandParameter="{Binding Value}" Content="{Binding Value}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
<Button Command="{Binding ButtonClickCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type viewModels:MainWindowVM}}}" CommandParameter="{Binding Value}" Content="{Binding Value}" />
Answer the question
In order to leave comments, you need to log in
Solved in this way:
<Button Margin="3" Command="{Binding DataContext.ButtonClickCommand, RelativeSource={RelativeSource AncestorType=ItemsControl}}" CommandParameter="{Binding Value}" Content="{Binding Value}" />
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question