Closed cornerbowlsoftware closed 4 months ago
I was able to get this working by adding my own string to key gesture converter:
<Style Selector="MenuItem" x:DataType="lib:MenuItemModel">
<Setter Property="Header" Value="{Binding Text}"/>
<Setter Property="Command" Value="{Binding Command}"/>
<Setter Property="InputGesture" Value="{Binding InputGestureText, Converter={StaticResource StringToKeyGestureConverter}}"/>
</Style>
Describe the bug
Most samples I see used hard coded axaml to generate menu items. This breaks the MVVM architecture, so first, I'm surprised to see the Avalonia documentation show menu item implementation in this manner. Second, when binding to an 'InputGesture' the value is not displayed. This bug likely would have been caught if the docs used MVVM instead of showing hard coded values.
To Reproduce
Create a ViewModel to house the data model:
Create a style to bind the various context menu items to a view model:
Next, define a context menu:
Run the app and display your control that hosts the menu items. Right click on the control. Notice the hot key, in this case "Ctrl+C" is not displayed. Put a breakpoint in the view model on InputGestureText. Reopen the view to regenerate the requests. Verify "Ctrl+C" is returned. Stop the program then change the style to hard code the InputGesture to "Ctrl+C" like so:
Rerun the application. Notice the InputGesture is displayed.
Expected behavior
The gesture should display.
Avalonia version
11.0.11
OS
Windows
Additional context
No response