【发布时间】:2015-07-08 10:40:52
【问题描述】:
我有一个包含 2 个 WPF 项目的项目解决方案。项目 B 在项目 A 中包含并调用。
我遇到的问题是项目 B MainWindow 上的按钮命令没有点击它对应的 ViewModel。当我将项目 B 作为独立应用程序运行时,这不会发生(一切都很好)。
在项目 A 和 B 中,我都使用 Galasofts MVVM 灯光框架,将我的视图模型存放在静态 ViewModelLocator 类中。
任何想法将不胜感激。 谢谢
编辑:为简单起见,我只添加了 1 个按钮。
ribbon:RibbonControl xmlns:Designer="clr-namespace:Nouvem.LabelDesigner.View.Designer" x:Class="Nouvem.LabelDesigner.View.Designer.DesignerView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ribbon="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:command="http://www.galasoft.ch/mvvmlight"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:systemMessage="clr-namespace:Nouvem.LabelDesigner.View.SystemMessage"
xmlns:loc="clr-namespace:Nouvem.Shared.Localisation;assembly=Nouvem.Shared"
UseLayoutRounding="True"
mc:Ignorable="d"
d:DesignHeight="1000" d:DesignWidth="1200"
Background="White"
DataContext="{Binding LabelDesigner, Source={StaticResource Locator}}" >
<Grid>
<Button Command="{Binding TestCommand}"/>
</Grid>
</ribbon:RibbonControl>
视图模型
public RelayCommand TestCommand { get; set; }
public LabelDesignerViewModel()
{
if (this.IsInDesignMode)
{
return;
}
this.TestCommand = new RelayCommand(() =>
{
// test - not hitting when called from another project
});
}
`
【问题讨论】:
-
您能否提供处理这些命令的代码的简单示例?请同时包含 XAML 和 C#。