2014-05-10 183 views
1

我试图将一组项目绑定到windowcommandsmetrowindow。以下是xaml片段。MahApps.Metro:WindowCommands ItemsSource绑定

<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财产,但有界的数据类型的类型名称。我怎样才能达到预期的行为?

回答

1

如果将模板作为资源添加到MetroWindow,则适用。为此,您需要创建一个具有标签和回调属性的WindowCommandViewModel。

<metro:MetroWindow.Resources> 
    <DataTemplate DataType="{x:Type viewModels:WindowCommandViewModel}"> 
     <Button Content="{Binding DisplayName}" 
       Command="{Binding Callback}"/> 
    </DataTemplate> 
</metro:MetroWindow.Resources>