问题描述:直接上代码,具体情况,代码行间有描述
<StackPanel Orientation="Vertical" Margin="0 0" Name="RootElement">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseEnter">
<i:InvokeCommandAction Command="{Binding MouseEnterCommand}" />
</i:EventTrigger>
/*
给StackPanel绑定三个鼠标事件(MouseEnter、MouseMove、MouseLeave),每个InvokeCommandAction
要带两种参数,
一种是MouseEventArgs,为此将PassEventArgsToCommand设置为True。
另外一种是附加参数,如果是附加参数只有一个,那么可以使用CommandParameter进行处理;但是考虑到有2个
或更多,所以使用了MultiBinding来处理附加参数,如下所示RootElement,WelcomeBorder都是UI元素,它们
都是作为附加参数来进行传递的。
换言之,有两种参数(MouseEventArgs + 附加参数),共三个参数
(MouseEventArgs+RootElement+WelcomeBorder)需要传到ViewModel中去。
但是让我困惑的是,我不知道如何在ViewModel中去接收界面中传过来参数,以及如何去触发鼠标事件
(如果只传一种参数,我知道如何在ViewModel中进行处理,这种复杂的,让我一时糊涂了)
*/
<i:EventTrigger EventName="MouseMove">
<i:InvokeCommandAction Command="{Binding MouseMoveCommand}" PassEventArgsToCommand="True">
<i:InvokeCommandAction.CommandParameter>
<MultiBinding Converter="{StaticResource ResourceKey=ObjectConvert}" Mode="TwoWay">
<MultiBinding.Bindings>
<Binding ElementName="RootElement" />
<Binding ElementName="WelcomeBorder" />
</MultiBinding.Bindings>
</MultiBinding>
</i:InvokeCommandAction.CommandParameter>
</i:InvokeCommandAction>
</i:EventTrigger>
<i:EventTrigger EventName="MouseLeave">
<i:InvokeCommandAction Command="{Binding MouseLeaveCommand}">
</i:InvokeCommandAction>
</i:EventTrigger>
</i:Interaction.Triggers>
<Border Name="WelcomeBorder" Margin="0 500 0 60" Padding="5" BorderThickness="1" BorderBrush="Black" Background="Black" CornerRadius="40" Width="1000">
<TextBlock Style="{StaticResource BaseMsgTextBlock}" FontSize="{Binding FontSizeScale,Converter={StaticResource CalcFontSize}, ConverterParameter=60}"
FontWeight="Bold" Text="{langs:Lang Key={x:Static langs:Lang.WelcomeText}}" Width="1000" TextAlignment="Center">
</TextBlock>
</Border>
</StackPanel>
我需要在InvokeCommandAction带多种参数进行传递,然后我不知道在viewmodel中如何去接收参数以及触发事件。
为此我查阅了一些资料,发现有一篇文章涉及这个问题,可惜的是,偏偏没有viewmodel层面的代码,这篇文章的网址为
https://blog.csdn.net/weixin_43235128/article/details/128345251
这篇文章中提到的“方式二”与我的情形甚是吻合,但是我不清楚,在viewmodel层面如何去处理。
提出问题: 签于我的这种情形,跟大家请教解决方案,期待大家的指点,感谢!