Avalonia
Avalonia copied to clipboard
Dynamically Generated MenuItem does not update `IsChecked` property of bound backing property.
Describe the bug
When Binding to a property using the <MenuItem.Styles>
or <MenuItem.ItemContainerTheme>
method, the IsChecked property does not stay in sync with its bound property.
- The underlying property is not updated when you check/uncheck the menu element (I could get around that with a command)
- The
IsChecked
property on the MenuItem does not get updated when the backing Property is changed, despite that property being aReactive
Property fromReactiveUI.Fody.Helpers
(which should implement INotifyPropertyChanged). This means that the Checkbox stays visible despite the fact that it should not.
To Reproduce
Use this code:
<MenuItem Header="_Windows" ItemsSource="{Binding WorkspaceWindows, Mode=OneWay}">
<MenuItem.ItemContainerTheme>
<ControlTheme TargetType="MenuItem" BasedOn="{StaticResource {x:Type MenuItem}}"
x:DataType="layout:WorkspaceWindowState">
<Setter Property="Command"
Value="{Binding $parent[MenuItem].((appnamespaces:WindowViewModel)DataContext).ToggleWindowCommand}" />
<Setter Property="CommandParameter" Value="{Binding .}" />
<Setter Property="Header" Value="{Binding Name}" />
<Setter Property="IsChecked" Value="{Binding IsVisible}" />
<Setter Property="ToggleType" Value="CheckBox" />
</ControlTheme>
</MenuItem.ItemContainerTheme>
</MenuItem>
The type of WorkSpaceWindows is an ObservableList of:
public class WorkspaceWindowState : ReactiveObject {
[Reactive]
public bool IsVisible { get; set; }
public string Name { get; set; } = string.Empty;
}
Expected behavior
Closing the window sets the value of IsVisible
to false
, so the IsChecked
Property of the MenuItem
should be set to false
too.
Avalonia version
11.1.3
OS
Windows
Additional context
No response