I'm trying to implement a custom command for a right-click menu item to allow the application to reinitialize a specific state. Following Heinzi's guidance in How do I add a custom routed command in WPF?, I've added the necessary XAML/bindings.
<UserControl.Resources>
<RoutedUICommand x:Key="UnsetCommand" Text="Reset" />
</UserControl.Resources>
<UserControl.CommandBindings>
<CommandBinding Command="{StaticResource UnsetCommand}" Executed="UnsetExecuted" />
</UserControl.CommandBindings>
<ContextMenu>
<MenuItem Command="{StaticResource UnsetCommand}" />
</ContextMenu>
And behind code
private void UnsetExecuted(object sender, ExecutedRoutedEventArgs e)
{
FreeResources();
Unset(false);
}
The issue I'm having is the menu item isn't enabled as expected.
Thoughts on what I'm missing here?
EDIT: Fixed typo UnsetsCommand -> UnsetCommand