mvvm-light RelayCommand没有开火

时间:2013-07-22 22:54:05

标签: c# ninject mvvm-light

我有一个使用Mvvm Light和Ninject的wpf应用程序。在我的本地机器上,RelayCommand工作正常,当我将应用程序移动到另一台服务器时,它不再调用该方法(消息框不会弹出)。

在MainViewModel.cs中我有

public ICommand GoClickCommand
{
    get
    {
        return new RelayCommand(() => MessageBox.Show("Directly in property!"), () => true);
    }
}

在MainWindow.xaml中我有

        `<Button Content="Go" HorizontalAlignment="Left" Margin="508,54,0,0" VerticalAlignment="Top" Width="75"
                Command="{Binding GoClickCommand}" IsDefault="True" Click="btn_go_Click"/>`

我在调用btn_go_click后面的代码中有一个方法,当单击该按钮时调用该方法,这只是为了确保按钮实际工作。我不确定它是否与Ninject有关。我正在尝试使应用程序自包含(只有一个.exe文件),因此我在App.xaml.cs文件中有代码来解决缺少的程序集。我尝试在没有此代码的情况下运行应用程序,应用程序需要的唯一2个程序集是GalaSoft.MvvmLight.WPF.dll和Ninject.dll。我注释掉了代码并将这两个程序集放在与应用程序相同的文件夹中,而RelayCommand仍未触发。实际应用程序中的代码更复杂,我更改了GoClickCommand属性中的代码以试图找出问题所在。感谢您提供任何帮助或建议。

//from http://www.paulrohde.com/merging-a-wpf-application-into-a-single-exe/
        {
            AppDomain.CurrentDomain.AssemblyResolve += OnResolveAssembly;
            App.Main();
        }

        private static Assembly OnResolveAssembly(object sender, ResolveEventArgs e)
        {
            var thisAssembly = Assembly.GetExecutingAssembly();

            //Get the name of the AssemblyFile
            var assemblyName = new AssemblyName(e.Name);
            var dllName = assemblyName.Name + ".dll";

            //Load from Embedded Resources - This function is not called if the Assembly is already
            //in the same folder as the app.
            var resources = thisAssembly.GetManifestResourceNames().Where(s => s.EndsWith(dllName));
            var resourcesEnumerated = resources as string[] ?? resources.ToArray();
            if (resourcesEnumerated.Any())
            {
                //99% of cases will only have one matching item, but if you don't,
                //you will have to change the logic to handle those cases.
                var resourceName = resourcesEnumerated.First();
                using (var stream = thisAssembly.GetManifestResourceStream(resourceName))
                {
                    if (stream == null) return null;
                    var block = new byte[stream.Length];

                    //Safely try to load the assembly
                    try
                    {
                        stream.Read(block, 0, block.Length);
                        return Assembly.Load(block);
                    }
                    catch (IOException ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    catch (BadImageFormatException ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
            //in the case where the resource doesn't exist, return null.
            return null;
        }
    }

0 个答案:

没有答案
相关问题