简体   繁体   English

特定字典元素作为CommandParameter

[英]Specific Dictionary Element as CommandParameter

    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Loaded">
            <i:InvokeCommandAction CommandParameter="{}" Command="{Binding ChangeViewModelCommand}"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>

In the ViewModel, itself, I have a Dictionary<string, IViewModel> defined which contains a reference to every ViewModel of the application. 在ViewModel本身中,我定义了Dictionary<string, IViewModel> ,其中包含对应用程序每个ViewModel的引用。 The property is ApplicationViewModels . 该属性是ApplicationViewModels From this command, is it possible to access a specific Dictionary entry of ApplicationViewModels ? 通过此命令,可以访问ApplicationViewModels的特定Dictionary条目吗?

The goal is to pass an already instantiated instance to the command. 目标是将已经实例化的实例传递给命令。

Yes, you can and it's very simple to do so: 是的,您可以并且这样做非常简单:

<i:Interaction.Triggers>
    <i:EventTrigger EventName="Loaded">
        <i:InvokeCommandAction CommandParameter="{Binding ApplicationViewModels[DictKey]}" Command="{Binding ChangeViewModelCommand}"/>
    </i:EventTrigger>
</i:Interaction.Triggers>

Where DictKey is the key of the viewmodel you're trying to pass. DictKey是您要传递的视图模型的键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM