I created a menu with a dynamic MenuItem list by doing the following:
<Menu VerticalAlignment="Top" Items="{Binding FileList}">
<Menu.ItemTemplate>
<DataTemplate>
<MenuItem Command="{Binding FileClick}" CommandParameter="{Binding FilePath}" Header="{Binding FileName}"/>
</DataTemplate>
</Menu.ItemTemplate>
</Menu>
But instead of showing the FileName in the header, it shows the class enter image description here
This is the var that contains the list of menu items:
[ObservableProperty]
public ObservableCollection<EditorMenuItem> fileList = new ObservableCollection<EditorMenuItem>();
And this is how I add an item into the list:
fileList.Add(new EditorMenuItem(
"test1",
"C:/test1.txt",
ReactiveCommand.Create<string>((string fileName) =>
{
HandleFileClick(fileName);
})
));
The EditorMenuItem class looks like this:
public class EditorMenuItem
{
public string FileName;
public string FilePath;
public ICommand FileClick;
public EditorMenuItem(string FileName, string FilePath, ICommand FileClick)
{
this.FileName = FileName;
this.FilePath = FilePath;
this.FileClick = FileClick;
}
}
Does anyone know what the problem is and why I get the className instead of the actual FileName?