Background:
I try to use Menu component of avaloniaUI in axaml.
Problem:
The Items property of Menu cannot be set in axaml.I don’t know why this happened.
The axaml code is following:
<Menu Items="{Binding Items}" DockPanel.Dock="Top" Background="AliceBlue">
<Menu.Styles>
<Style Selector="MenuItem">
<Setter Property="Header" Value="{Binding Header}"/>
</Style>
</Menu.Styles>
</Menu>
The main code in code-behind is following:
var menu = new MenuMainViewModel();
menu.MenuItems = new MenuItemViewModel[]
{
new MenuItemViewModel
{
Header="file",
Items=new MenuItemViewModel[]
{
new MenuItemViewModel {
Header="startNew",
},
}
},
};
The error message of Menu component in axaml is following:
Unable to find suitable setter or adder for property items of type Avalonia.Controls:Avalonia.Controls.itemControl for argument
Avalonia.Markup:Avalonia.Data.Binding, available setter parameter lists are:
Svstem.obieasvstem.0bect line 10, position 9.
Tring :
I find the avalonia’s official document for Menu component.The Menu component had Items property as following.
enter image description here
But I don’t know why it can’t be set.
helloworld is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.