首页 新闻 会员 周边

wpf 绑定的问题

0
悬赏园豆:10 [已解决问题] 解决于 2013-06-28 10:03

现在是这样,我用mvvm框架写的程序,出现了一个问题,ViewMode层是类嵌套类的关系,假设

 1     class DataPresentCategoryViewModel:NotificationObject
 2     {
 3 
 4         public DataPresentCategoryViewModel()
 5         {
 6             LoadCategoryViewModel load = new LoadCategoryViewModel();
 7             load.LoadDataCategory = new List<LoadDataCategoryViewModel>();
 8         }
 9         private string _iskName;
10 
11         public string ISKName
12         {
13             get { return _iskName; }
14             set
15             {
16                 _iskName = value;
17                 this.RaisePropertyChanged("ISKName");
18             }
19         }
20 
21         private int _selectedScientificLoadName;
22 
23         public int SelectedScientificLoadName
24         {
25             get { return _selectedScientificLoadName; }
26             set
27             {
28                 _selectedScientificLoadName = value;
29                 this.RaisePropertyChanged("SelectedScientificLoadName");
30             }
31         }
32 
33         private int _selectedEngineeringLoadName;
34 
35         public int SelectedEngineeringLoadName
36         {
37             get { return _selectedEngineeringLoadName; }
38             set
39             {
40                 _selectedEngineeringLoadName = value;
41                 this.RaisePropertyChanged("SelectedEngineeringLoadName");
42             }
43         }
44 
45         private LoadCategoryViewModel _presentLoadCategory;
46 
47         public LoadCategoryViewModel PresentLoadCategory
48         {
49             get { return _presentLoadCategory; }
50             set
51             {
52                 _presentLoadCategory = value;
53                 this.RaisePropertyChanged("PresentLoadCategory");
54             }
55         }
56     }
57 }

行中 47 是被此类封装的另一个类。

现在按照msdn上绑定的介绍,我在MainWindow中直接对windows.dataContent进行引用赋值

1         public MainWindow()
2         {
3             InitializeComponent();
4             this.DataContext = new DataPresentCategoryViewModel();
5         }

 现在在xaml界面我需要对DataPresentCategoryViewModel类中的LoadCategoryViewModel里面的内容进行调用,

{..........Visibility="{Binding IsVisable, Mode=TwoWay}

红色部分应该怎么写,问题出在这里,我不知道对象下面的属性,怎么调用,还是这种绑定的用法不对,我只是想把界面通过xml持久化,并且更容易的改变配置。

diorlv的主页 diorlv | 菜鸟二级 | 园豆:259
提问于:2012-05-16 18:27
< >
分享
最佳答案
0

这里有个问题,

你构造函数里创建的LoadCategoryViewModel与你的属性LoadCategoryViewModel不是一个对象,你应该找不到在构造函数里赋的值。

除非在构造函数里这样写:

this.PresentLoadCategory=new LoadCategoryViewModel();
this.PresentLoadCategory.LoadDataCategory = new List<LoadDataCategoryViewModel>();

绑定就比较简单了,因为你用的时数据上下文,所以:

{..........Visibility="{Binding PresentLoadCategory.LoadDataCategory[Index], Mode=TwoWay}

收获园豆:10
中文代码 | 小虾三级 |园豆:951 | 2012-05-18 08:55
其他回答(1)
0

正如楼上所说没有赋值,PresentLoadCategory.IsVisable

Lee's Blog | 园豆:530 (小虾三级) | 2012-07-01 22:30
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册