【问题标题】:MahApps.Metro: WindowCommands ItemsSource bindingMahApps.Metro:WindowCommands ItemsSource 绑定
【发布时间】:2014-06-19 15:17:04
【问题描述】:

我正在尝试将一组项目绑定到metrowindowwindowcommands。下面是 xaml sn-p。

<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 属性,而是显示有界数据类型的类型名称。我怎样才能达到预期的行为?

【问题讨论】:

    标签: wpf mahapps.metro


    【解决方案1】:

    如果您将模板作为资源添加到 MetroWindow,则可以使用。为此,您需要创建一个具有 Label 和 Callback 属性的 WindowCommandViewModel。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-07
      • 1970-01-01
      • 2011-12-17
      • 2011-10-26
      • 2011-01-14
      • 2018-08-27
      • 2012-01-08
      • 1970-01-01
      相关资源
      最近更新 更多