【发布时间】:2011-08-24 11:33:53
【问题描述】:
大家好,我正在使用 SL4 和 MVVM 应用程序,实际上我被困在一些地方,我可能做错了什么,这就是为什么需要你的帮助,这是我的场景
//suodo code
public class EmployeeModel
{
//code
Public List<Shifts> Employeeshifts{get;set;}
}
public class ShiftModel
{
//code
}
主页面的视图模型
public class MainVM
{
MainVM()
{
EmployeeList = DateFromSomeService;
}
Public List<Employees> EmployeeList{get;set}
Public DelegateCommand ClickBindingCommand{get;set;}
}
MainPage.xaml
<ItemsControl ItemSource={Binding EmployeeList}>
<ItemTemplate>
<DataTemplate>
<controls:EmployeeControl/>
</DataTemplate>
</ItemTemplate>
</ItemsControl>
Employeecontro.xaml
<ItemsControl ItemSource={Binding EmployeeShifts}>
<ItemTemplate>
<DataTemplate>
<controls:ShiftControl Click={Binding ClickBindingCommand}/>//here is problem this command is in mainviewmodel
</DataTemplate>
</ItemTemplate>
</ItemsControl>
MainPage.cs
this.DataContext = new MainVM();
ClickBindingCommand 是在主 VM 中定义的,但它绑定在班次控制中,班次控制的数据上下文是班次类,这是我的模型类。如果我在我的班次模型类中声明这个命令而不是它的工作,意味着如果我点击班次控制这个属性被调用但我不想要这个,因为我想在我的主视图模型中,我错在哪里?
我应该在我的班次模型类中声明它,但这样我会直接将我的模型绑定到我的视图吗?
【问题讨论】:
-
请将您的问题标题更新为与您的问题更相关的内容 - 它目前只是标签列表,属于“标签”部分。
标签: silverlight-4.0 mvvm mvvm-light