I have a ContextMenu for TreeView items declared in the treeview:
<TreeView ItemsSource="{Binding countries, Mode=TwoWay}" SelectedItemChanged="TreeView_SelectedItemChanged">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type myapp:City}" ItemsSource="{Binding Cities}">
<StackPanel Orientation="Horizontal" ContextMenu="{StaticResource CityItem}">
<TextBlock Text="{Binding CityName}" FontSize="14" Foreground="Bisque"/>
...
And the ContextMenu itself declared as:
<ContextMenu x:Key ="CityItem" StaysOpen="true" Foreground="Bisque">
<MenuItem Header="Edit City" CommandParameter="{Binding Parent, RelativeSource={RelativeSource Self}}" Click="EditCityClick"/>
<MenuItem Header="DeleteCity" CommandParameter="{Binding Parent, RelativeSource={RelativeSource Self}}" Click="DeleteCityClick"/>
</ContextMenu>
Well, at this point everything is working
private void DeleteCityClick(object sender, RoutedEventArgs e)
{
City city = ((FrameworkElement)e.OriginalSource).DataContext as City;
...
}
I can access to the city object, modify, delete, whatever and everything is updated in the gui acording to the changes in Cities and City properties (onpropertychanged is working fine).
The question is how can i disable a ContextMenuItem binding IsEnabled to a City object property? Let's say
public bool IsEnabled { get; set;}
I tried several ways, but idk how to access to the source object (City) from the ContextMenu MenuItem.
Thanks!
Edited: Sorry for the typo but:
public string IsEnabled { get; set;}
Actually is:
public bool IsEnabled { get; set;}
Edit 2:
Funny "not a wpf..."