当wpf在进行binding时如果要绑定的内容是dataContext中一个成员属性中成员属性时,一开始网上查了半天没找到相关东西,最后老老实实翻书才发现只要简单的A.B 就好了。哎真是用wpf的开发太少基础功不好阿。实际大体例子如下:
public class Teacher{
public string name {set;get;}
}
public class Student{
public Teacher teacher {set;get;}
public int Id {set;get;}
}
在xaml中时行binding时需要这样写
<StackPanel x:Name="container">
<TextBlock Text="学号:" />
<TextBlock Text="{Binding Id}" />
<TextBlock Text="老师:" />
<TextBlock Text="{Binding teacher.name}" />
</StackPanel>
windows类中代码:
public partial class TestBindWindow:Window
{
private Student student = new student();
public TestBindWindow(){
InitializeComponent();
this.container.DataContext =student
}
}
博客主要讲述了在WPF进行binding时,若要绑定dataContext中一个成员属性的成员属性,通过查书发现只需用A.B的方式即可。还提到用WPF开发的人较少,基础功可能不足,并给出了在xaml中进行binding的示例。
1万+

被折叠的 条评论
为什么被折叠?



