【问题标题】:how to pass generic list in CommandParameter如何在 CommandParameter 中传递通用列表
【发布时间】:2013-06-13 10:23:32
【问题描述】:

我有使用以下代码从我的 XAML(视图)执行的命令:

<HyperlinkButton Command="{Binding DataContext.HyperlinkGoToCommand,  RelativeSource={RelativeSource AncestorType=UserControl}}" CommandParameter="ABCD">
  <TextBlock Text="ABCD" TextDecorations="Underline"/></HyperlinkButton>

目前 CommandParameter 作为字符串传递,它工作正常,但我想将 CommandParameter 作为 List (单项通用列表)而不是字符串传递。

【问题讨论】:

  • 如果您的命令和通用列表在同一个视图模型中,则根本不需要命令参数。所以请提供更多信息

标签: c# wpf silverlight mvvm


【解决方案1】:

如果您想从 (XAML) 控件中绑定集合,例如来自组合框:

<ComboBox x:name="combobox" ItemsSource="{Binding Collection}">
<HyperlinkButton Command="{Binding DataContext.HyperlinkGoToCommand}", CommandParameter="{Binding  ElementName=combobox, Path=ItemsSource}"></HyperlinkButton>

如果你想从 ViewModel 绑定集合:

CommandParameter="{Binding DataContext.YourCollectionPropertyFromViewModel}" or
CommandParameter="{Binding YourCollectionFromViewModel}"

查看answer 了解更多详细说明。

问候,

【讨论】:

    猜你喜欢
    • 2012-05-13
    • 2016-04-27
    • 1970-01-01
    • 2012-12-14
    • 2022-01-26
    • 2015-09-13
    • 1970-01-01
    • 1970-01-01
    • 2012-09-04
    相关资源
    最近更新 更多