标签:ext article ring store anim pre ado blog static
原文:WPF 精修篇 数据绑定到对象
数据绑定到对象
首先 我们需要一个对象
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
设置依赖属性绑定数据上下文
-
-
-
-
Preson = new Preson() { Name = "慧哥", Address = "大连", Age = 30 };
-
-
-
-
-
-
-
-
get { return (Preson)GetValue(PresonProperty); }
-
set { SetValue(PresonProperty, value); }
-
-
-
// Using a DependencyProperty as the backing store for Preson. This enables animation, styling, binding, etc...
-
public static readonly DependencyProperty PresonProperty =
-
DependencyProperty.Register("Preson", typeof(Preson), typeof(MainWindow), new PropertyMetadata(null));
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
"Left" Height="23" Margin="101,27,0,0" Grid.Row="1" TextWrapping="Wrap" Text="{Binding Age,Mode=TwoWay}" VerticalAlignment="Top" Width="120" Grid.ColumnSpan="2" />
-
"Left" Margin="41,22,0,0" TextWrapping="Wrap" Text="名字" VerticalAlignment="Top"/>
-
"Left" Margin="79,22,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Text="{Binding Name}" Width="30"/>
-
"Left" Margin="10,22,0,0" TextWrapping="Wrap" Text="address" VerticalAlignment="Top" Grid.Column="1"/>
-
"63.667,22,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Text="{Binding Address}" Grid.Column="1"/>
-
"Left" Margin="20,22,0,0" TextWrapping="Wrap" Text="age" VerticalAlignment="Top" Grid.Column="2"/>
-
"57,22,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Text="{Binding Age}" Grid.Column="2"/>
-
"Left" Height="23" Margin="0,17,0,0" Grid.Row="1" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Grid.ColumnSpan="2" Grid.Column="2" />
-
前台WPF绑定
这里也可以用 INotifyPropertyChanged 也可以
集合使用ObservableCollenction
WPF 精修篇 数据绑定到对象
标签:ext article ring store anim pre ado blog static
原文地址:https://www.cnblogs.com/lonelyxmas/p/12075447.html