[b]让控件更灵活的Data Template[/b]
这段代码可以给一个ListView的一列做双向绑定,并且指定这一行的渲染控件。
[b]比Windows Forms更强的Binding[/b]
DependencyObject + DependencyProperty使得属性设置可以自动触发ValueChanged事件,从而让Binding进行更新。
[b]让排版更灵活的各种Layout控件[/b]
对于普通界面的排版,用Grid+Border
对于要动态添加删除的界面排版,在需要动态增删的位置使用StackPanel
GridViewColumn gvcName = new GridViewColumn();
gvcName.Header = "Name";
DataTemplate nameTemplate = new DataTemplate();
FrameworkElementFactory nameFactory = new FrameworkElementFactory(typeof(ContactPropertyLabel));
Binding binding = new Binding("Name");
binding.Mode = BindingMode.TwoWay;
nameFactory.SetBinding(ContentProperty, binding);
nameTemplate.VisualTree = nameFactory;
gvcName.CellTemplate = nameTemplate;
gvContactList.Columns.Add(gvcName);
这段代码可以给一个ListView的一列做双向绑定,并且指定这一行的渲染控件。
[b]比Windows Forms更强的Binding[/b]
public class Contact : DependencyObject
{
public static DependencyProperty NameProperty = DependencyProperty.Register("Name", typeof (string), typeof (Contact));
public string Name
{
get { return (string) GetValue(NameProperty); }
set { SetValue(NameProperty, value); }
}
}
DependencyObject + DependencyProperty使得属性设置可以自动触发ValueChanged事件,从而让Binding进行更新。
[b]让排版更灵活的各种Layout控件[/b]
对于普通界面的排版,用Grid+Border
对于要动态添加删除的界面排版,在需要动态增删的位置使用StackPanel