在" windows app"中传递事件参数的简单方法使用MVVMLight

时间:2015-06-30 01:56:28

标签: c# mvvm windows-8.1

我遇到一个问题,即使用MVVMLight将参数从事件(View / XAML)传递给viewmodel。如何将事件参数传递给命令?我目前正在使用

xmlns:Interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:Core="using:Microsoft.Xaml.Interactions.Core"
xmlns:mvvm="http://www.galasoft.ch/mvvmlight" 

<Grid>                
   <Interactivity:Interaction.Behaviors>                    
      <Core:EventTriggerBehavior EventName="Loaded">                        
      <Core:InvokeCommandAction Command="{Binding ICommandLoaded, Mode=OneWay}" CommandParameter="{Binding args}" />
      </Core:EventTriggerBehavior>
   </Interactivity:Interaction.Behaviors>
<Grid/>

所以在我的viewModel中,我有

public ICommand ICommandLoaded { get; private set; }
ICommandLayerLoaded = new RelayCommand(() => Grid_Loaded(null, null));
public void Grid_LayerLoaded(object sender, RoutedEventArgs e)
{...}

如何将senderObject和RoutedEventArgs传递给Grid_LayerLoaded类?不是将其设置为null,而是null。

我遇到了这个解决方案

https://marcominerva.wordpress.com/2014/01/10/windows-8-1-behavior-sdk-how-to-use-invokeaction-with-inputconverter-to-pass-arguments-to-a-command/

是否有必要为这么简单的任务创建一个转换器?有没有更好的方法来做到这一点。 (请注意,这是在windowsApp中没有EventToCommand

http://blog.galasoft.ch/posts/2014/01/using-the-eventargsconverter-in-mvvm-light-and-why-is-there-no-eventtocommand-in-the-windows-8-1-version/

0 个答案:

没有答案