Wpf Metro:WindowCommands项资源绑定
我正在尝试将项目集合绑定到Wpf Metro:WindowCommands项资源绑定,wpf,mahapps.metro,Wpf,Mahapps.metro,我正在尝试将项目集合绑定到metrowindow的windowcommands。下面是xaml代码片段 <metro:MetroWindow.WindowCommands> <metro:WindowCommands ItemsSource="{Binding WindowCommands}"> <ItemsControl.ItemTemplate> <DataTe
metrowindow
的windowcommands
。下面是xaml代码片段
<metro:MetroWindow.WindowCommands>
<metro:WindowCommands ItemsSource="{Binding WindowCommands}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Content="{Binding DisplayName}"
Command="{Binding Callback}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</metro:WindowCommands>
</metro:MetroWindow.WindowCommands>
但它不显示
DisplayName
属性,而是显示绑定数据类型的类型名称。如何实现预期的行为?如果将模板作为资源添加到MetroWindow中,则可以正常工作。为此,您需要创建一个具有标签和回调属性的WindowCommandViewModel
<metro:MetroWindow.Resources>
<DataTemplate DataType="{x:Type viewModels:WindowCommandViewModel}">
<Button Content="{Binding DisplayName}"
Command="{Binding Callback}"/>
</DataTemplate>
</metro:MetroWindow.Resources>