You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
public class MenuItemViewmModel : BaseViewModel
{
public string? Text { get; set; }
public ICommand? Command { get; set; }
public string? Icon { get; set; }
public string? InputGestureText { get; set; }
protected MenuItemViewModel()
{
}
public MenuItemViewModel(string text)
{
Text = text;
}
public MenuItemViewModel(string text, string? icon)
: this(text)
{
Icon = icon;
}
public MenuItemViewModel(string text, string? icon, ICommand? command)
: this(text, icon)
{
Command = command;
}
public MenuItemViewModel(string text, string? icon, ICommand? command, string inputGestureText)
: this(text, icon, command)
{
InputGestureText = inputGestureText;
}
public override string? ToString() => Text;
public static object? Children => null;
}
Create a style to bind the various context menu items to a view model:
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:
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
The text was updated successfully, but these errors were encountered: