在MVVM-Light工具包中使用EventToCommand时如何传递多个参数和EventArgs属性

发布于 2024-09-14 22:47:51 字数 147 浏览 3 评论 0原文

我正在为我的 WPF 应用程序使用 MVVM Light 工具包,我想知道在使用 EventToCommand 时是否可以将多个参数传递给 RelayCommand 以及是否可以传递 EventArgs 的属性而不是传递整个 EventArgs ?

问候, 纳比尔

I am using MVVM Light toolkit for my WPF application and I would like to know if its possible, when using EventToCommand, to pass multiple parameters to RelayCommand and Is it possible to pass properties of EventArgs instead of passing the whole EventArgs ?

Regards,
Nabeel

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

奢华的一滴泪 2024-09-21 22:47:51

如果场景是

 <i:Interaction.Triggers>
                <i:EventTrigger EventName="KeyDown">
                    <cmd:EventToCommand Command="{Binding SearchKey}" PassEventArgsToCommand="True" 
                    CommandParameter="{Binding Text, ElementName=TextSearchCashDrawer}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>

按下回车键时的情况,我需要从文本框中读取文本并执行搜索。

        SearchKey=new RelayCommand<KeyEventArgs>(e=>
                                                     {
                                                         if(e.PlatformKeyCode==13) //enter key
                                                         {


                                                         }
                                                     });

使用这个我可以过滤按下了哪个键,但是如果在此 mvvmlight 中按下 Enter 键,如何获取该参数。

what if the scenario is

 <i:Interaction.Triggers>
                <i:EventTrigger EventName="KeyDown">
                    <cmd:EventToCommand Command="{Binding SearchKey}" PassEventArgsToCommand="True" 
                    CommandParameter="{Binding Text, ElementName=TextSearchCashDrawer}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>

what is on enter key press i need to read the text from the textbox and perform search.

        SearchKey=new RelayCommand<KeyEventArgs>(e=>
                                                     {
                                                         if(e.PlatformKeyCode==13) //enter key
                                                         {


                                                         }
                                                     });

using this I can filter which key has been pressed but how to get that parameter if enter key is pressed in this mvvmlight.

北笙凉宸 2024-09-21 22:47:51

如果您只想捕获回车键按下的情况,则可以通过 InputBinding 创建 KeyBinding。下面的 XAML 示例将捕获 TextBox 中的 Enter 按键,而命令(本例中为 FindCommand)将在 ViewModel 中处理它。

<TextBox Width="80">
     <TextBox.InputBindings>
          <KeyBinding Key="Enter" Command="{Binding FindCommand}" />
     </TextBox.InputBindings>
</TextBox>

为我工作!

If all you want to do is capture the enter key press, you can create a KeyBinding via InputBinding. The following example in XAML would capture the Enter key press in the TextBox and the Command, FindCommand in this case, would handle it in your ViewModel.

<TextBox Width="80">
     <TextBox.InputBindings>
          <KeyBinding Key="Enter" Command="{Binding FindCommand}" />
     </TextBox.InputBindings>
</TextBox>

Worked for me!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文