WPF4不支持MvvmLight EventToCommand?

时间:2016-02-15 20:19:23

标签: c# .net wpf mvvm mvvm-light

我制作了超级简单的演示项目,以显示我的问题。我只有一个视图和viewmodel和两个nuget包。 MainWindowMainWindowViewModelExpression.Blend.SdkMvvmLightLibs

我的套餐:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="CommonServiceLocator" version="1.3" targetFramework="net452" />
  <package id="Expression.Blend.Sdk" version="1.0.2" targetFramework="net452" />
  <package id="MvvmLightLibs" version="5.2.0.0" targetFramework="net452" />
</packages>

C#代码,所以App和ViewModel:

public partial class App : Application
{
    protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);
        MainWindow mainWindow = new MainWindow();
        mainWindow.Show();
    }
}

public class MainWindowViewModel : ObservableObject
{
    public string Title => "Main window";
    public ICommand LoadedCommand => new RelayCommand(Loaded);

    private void Loaded()
    {
        Debug.WriteLine("Loaded");
    }
}

和MainWindow.xaml:

<Window x:Class="MvvmDemo1.WPF.Views.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:MvvmDemo1.WPF.Views"
        mc:Ignorable="d"
        Title="MainWindow" Height="300" Width="300"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:cmd="http://www.galasoft.ch/mvvmlight"
        xmlns:viewModels="clr-namespace:MvvmDemo1.WPF.ViewModels">
    <Window.DataContext>
        <viewModels:MainWindowViewModel />
    </Window.DataContext>
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Loaded">
            <cmd:EventToCommand Command="{Binding Mode=OneWay, Path=LoadedCommand}" 
                                        PassEventArgsToCommand="True" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
    <Grid>
        <Label x:Name="Label" HorizontalAlignment="Left" Margin="82,78,0,0" VerticalAlignment="Top"
               Content="{Binding Title}"/>
    </Grid>
</Window>

这是我的问题:

  

类型&#39; EventToCommand&#39;来自汇编&#39; GalaSoft.MvvmLight.Platform&#39;   是使用旧版本的Blend SDK构建的,不受支持   在Windows Presentation Framework 4项目中。

enter image description here

问题是,你能帮我解决这个问题吗?

顺便说一下。我有这个:

xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:cmd="http://www.galasoft.ch/mvvmlight"

因为他们建议on mvvmlight webpage(页面底部)

0 个答案:

没有答案
相关问题