2009-09-16 89 views
0

结合我已经得到了有NotesViewModelWPF - MVVM命令的子视图模型

public IManageVehicleNotesViewModel NotesViewModel { get; set; } 

子视图模型在VehicleViewModel第一次激活我激活子视图模型一个VehicleViewModel。

NotesViewModel.Activate(); 

该激活调用一个方法来初始化一些命令,我​​已经指出这个和它被调用。

CreateCommand = new DelegateCommand<object>(OnCreateCommand, CanCreate); 

然而,尽管文本框是在副视点(这样的DataContext到位)没有命令是绑定绑定 - 我试着呼唤RaiseCanExecuteChanged上的命令,但他们没有禁用,启用或按预期调用方法。

我不知道它是否有关(如文本框被结合),但我的关联查看和使用视图模型ResourceDictionary中的那么...在顶层VehicleViewModel

<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:v="clr-namespace:GTS.GRS.N3.Modules.Vehicles.Views" 
    xmlns:vm="clr-namespace:GTS.GRS.N3.Modules.Vehicles.Model"> 
    <DataTemplate DataType="{x:Type vm:ManageVehicleViewModel}"> 
    <v:ManageVehicleView /> 
    </DataTemplate> 
    <DataTemplate DataType="{x:Type vm:ManageVehicleNotesViewModel}"> 
    <v:ManageVehicleNotesView /> 
    </DataTemplate> 
</ResourceDictionary> 

的命令工作。

有没有人遇到类似这样的事情?这是我做事的顺序吗?任何帮助感激地收到!

干杯,

安迪

回答

2

是否CreateCommand属性触发事件PropertyChanged?如果没有,用户界面不会当你将它通知...

尝试使用工具,如Snoop检查按钮的Command属性是否设置

+0

尼斯一个感谢,以前我从来没有必须在命令上有一个PropertyChanged,但我刚刚refactered我的模块。我想到了RaiseCanExecuteChanged是PropertyChanged for Commands的替代品,谢谢指针! – 2009-09-16 15:41:03

+0

如果命令定义前先查看被绑定到视图模型,你不需要提高的PropertyChanged。无论如何,我的命令属性通常是只读的,而且是初始化的,所以我不需要担心它 – 2009-09-16 16:05:46

0

做到这一点,检查输出,看看是怎么回事:

<UserControl … 
    xmlns:diagnostics="clr-namespace:System.Diagnostics;assembly=WindowsBase" /> 

<Button Command="{Binding MyCommand, 
        diagnostics:PresentationTraceSources.TraceLevel=High}" … /> 

应该报什么对象,但它实际上是试图绑定到,等检查您在运行时的输出窗口,以查看该绑定发生了什么。