如何理解WPF中的c 依赖属性项属性

如何理解WPF中的依赖项属性_百度知道
如何理解WPF中的依赖项属性
我有更好的答案
送梓州李使君(王维)
为您推荐:
其他类似问题
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。WPF(依赖属性)
&Window x:Class=&TestOfFirstDependencyObject.MainWindow&&
&&&&&&& xmlns=&https://schemas.microsoft.com/winfx/2006/xaml/presentation&&
&&&&&&& xmlns:x=&https://schemas.microsoft.com/winfx/2006/xaml&&
&&&&&&& Title=&MainWindow& Height=&350& Width=&525&&&
&&& &StackPanel &&
&&&&&&& &TextBox x:Name=&textBox1& BorderBrush=&Black& Margin=&5& /&&
&&&&&&& &TextBox x:Name=&textBox2& BorderBrush=&Black& Margin=&5& /&&
&&&&&&& &Button Content=&OK& Margin=&5& Click=&Button_Click& /&&
&&& &/StackPanel&&
&/Window&&
&Window x:Class=&TestOfFirstDependencyObject.MainWindow&
&&&&&&& xmlns=&https://schemas.microsoft.com/winfx/2006/xaml/presentation&
&&&&&&& xmlns:x=&https://schemas.microsoft.com/winfx/2006/xaml&
&&&&&&& Title=&MainWindow& Height=&350& Width=&525&&
&&& &StackPanel &
&&&&&&& &TextBox x:Name=&textBox1& BorderBrush=&Black& Margin=&5& /&
&&&&&&& &TextBox x:Name=&textBox2& BorderBrush=&Black& Margin=&5& /&
&&&&&&& &Button Content=&OK& Margin=&5& Click=&Button_Click& /&
&&& &/StackPanel&
using System.W&
using System.Windows.C&
using System.Windows.D&
namespace TestOfFirstDependencyObject&
&&& /// &summary&&&
&&& /// Interaction logic for MainWindow.xaml&&
&&& /// &/summary&&&
&&& public partial class MainWindow : Window&
&&&&&&& private S&
&&&&&&& public MainWindow()&
&&&&&&& {&
&&&&&&&&&&& InitializeComponent();&
&&&&&&&&&&& stu = new Student();&
&&&&&&&&&&& //Binding binding = new Binding(&Text&)&&
&&&&&&&&&&& //&&&&&&&&&&&&&&&&&&&&& {&&
&&&&&&&&&&& //&&&&&&&&&&&&&&&&&&&&&&&&& Source = textBox1&&
&&&&&&&&&&& //&&&&&&&&&&&&&&&&&&&&& };&&
&&&&&&&&&&& //BindingOperations.SetBinding(stu, Student.NameProperty, binding);&&
&&&&&&&&&&& stu.SetBinding(Student.NameProperty, new Binding(&Text&)&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& {&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Source = textBox1&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& });&
&&&&&&&&&&& textBox2.SetBinding(TextBox.TextProperty, new Binding(&Name&)&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& {&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Source = stu&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& });&
&&&&&&& }&
&&&&&&& private void Button_Click(object sender, RoutedEventArgs e)&
&&&&&&& {&
&&&&&&&&&&& //Student stu = new Student();&&
&&&&&&&&&&& //stu.SetValue(Student.NameProperty,this.textBox1.Text);&&
&&&&&&&&&&& //textBox2.Text = stu.GetValue(Student.NameProperty)&&
&&&&&&&&&&& //MessageBox.Show(stu.GetValue(Student.NameProperty).ToString());&&
&&&&&&&&&&& //Student stu = new Student();&&
&&&&&&&&&&& //stu.Name = textBox1.T&&
&&&&&&&&&&& //this.textBox2.Text = stu.N&&
&&&&&&& }&
&&& public class Student : DependencyObject&
&&&&&&& public static readonly DependencyProperty NameProperty =&
&&&&&&&&&&& DependencyProperty.Register(&Name&, typeof(string), typeof(Student));&
&&&&&&& public string Name&
&&&&&&& {&
&&&&&&&&&&& get { return (string)GetValue(NameProperty); }&
&&&&&&&&&&& set { SetValue(NameProperty, value); }&
&&&&&&& }&
&&&&&&& public int Age&
&&&&&&& {&
&&&&&&&&&&& get { return (int)GetValue(AgeProperty); }&
&&&&&&&&&&& set { SetValue(AgeProperty, value); }&
&&&&&&& }&
&&&&&&& // Using a DependencyProperty as the backing store for Age.& This enables animation, styling, binding, etc...&&
&&&&&&& public static readonly DependencyProperty AgeProperty =&
&&&&&&&&&&& DependencyProperty.Register(&Age&, typeof(int), typeof(Student), new UIPropertyMetadata(0));&
&&&&&&& public BindingExpressionBase SetBinding(DependencyProperty dp, BindingBase binding)&
&&&&&&& {&
&&&&&&&&&&& return BindingOperations.SetBinding(this, dp, binding);&
&&&&&&& }&
&&&&&&& public static readonly DependencyProperty IdProperty = DependencyProperty.Register(&Id&, typeof(int), typeof(Student));&
&&&&&&& public int Id&
&&&&&&& {&
&&&&&&&&&&& get { return (int)this.GetValue(IdProperty); }&
&&&&&&&&&&& set { this.SetValue(IdProperty, value); }&
&&&&&&& }&
&&&&&&& public string School&
&&&&&&& {&
&&&&&&&&&&& get { return (string)GetValue(SchoolProperty); }&
&&&&&&&&&&& set { SetValue(SchoolProperty, value); }&
&&&&&&& }&
&&&&&&& // Using a DependencyProperty as the backing store for School.& This enables animation, styling, binding, etc...&&
&&&&&&& public static readonly DependencyProperty SchoolProperty =&
&&&&&&&&&&& DependencyProperty.Register(&School&, typeof(string), typeof(Student), new UIPropertyMetadata(&&));&
using System.W
using System.Windows.C
using System.Windows.D
namespace TestOfFirstDependencyObject
&&& /// &summary&
&&& /// Interaction logic for MainWindow.xaml
&&& /// &/summary&
&&& public partial class MainWindow : Window
&&&&&&& private S
&&&&&&& public MainWindow()
&&&&&&&&&&& InitializeComponent();
&&&&&&&&&&& stu = new Student();
&&&&&&&&&&& //Binding binding = new Binding(&Text&)
&&&&&&&&&&& //&&&&&&&&&&&&&&&&&&&&& {
&&&&&&&&&&& //&&&&&&&&&&&&&&&&&&&&&&&&& Source = textBox1
&&&&&&&&&&& //&&&&&&&&&&&&&&&&&&&&& };
&&&&&&&&&&& //BindingOperations.SetBinding(stu, Student.NameProperty, binding);
&&&&&&&&&&& stu.SetBinding(Student.NameProperty, new Binding(&Text&)
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Source = textBox1
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& });
&&&&&&&&&&& textBox2.SetBinding(TextBox.TextProperty, new Binding(&Name&)
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Source = stu
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& });
&&&&&&& private void Button_Click(object sender, RoutedEventArgs e)
&&&&&&&&&&& //Student stu = new Student();
&&&&&&&&&&& //stu.SetValue(Student.NameProperty,this.textBox1.Text);
&&&&&&&&&&& //textBox2.Text = stu.GetValue(Student.NameProperty)
&&&&&&&&&&& //MessageBox.Show(stu.GetValue(Student.NameProperty).ToString());
&&&&&&&&&&& //Student stu = new Student();
&&&&&&&&&&& //stu.Name = textBox1.T
&&&&&&&&&&& //this.textBox2.Text = stu.N
&&& public class Student : DependencyObject
&&&&&&& public static readonly DependencyProperty NameProperty =
&&&&&&&&&&& DependencyProperty.Register(&Name&, typeof(string), typeof(Student));
&&&&&&& public string Name
&&&&&&&&&&& get { return (string)GetValue(NameProperty); }
&&&&&&&&&&& set { SetValue(NameProperty, value); }
&&&&&&& public int Age
&&&&&&&&&&& get { return (int)GetValue(AgeProperty); }
&&&&&&&&&&& set { SetValue(AgeProperty, value); }
&&&&&&& // Using a DependencyProperty as the backing store for Age.& This enables animation, styling, binding, etc...
&&&&&&& public static readonly DependencyProperty AgeProperty =
&&&&&&&&&&& DependencyProperty.Register(&Age&, typeof(int), typeof(Student), new UIPropertyMetadata(0));
&&&&&&& public BindingExpressionBase SetBinding(DependencyProperty dp, BindingBase binding)
&&&&&&&&&&& return BindingOperations.SetBinding(this, dp, binding);
&&&&&&& public static readonly DependencyProperty IdProperty = DependencyProperty.Register(&Id&, typeof(int), typeof(Student));
&&&&&&& public int Id
&&&&&&&&&&& get { return (int)this.GetValue(IdProperty); }
&&&&&&&&&&& set { this.SetValue(IdProperty, value); }
&&&&&&& public string School
&&&&&&&&&&& get { return (string)GetValue(SchoolProperty); }
&&&&&&&&&&& set { SetValue(SchoolProperty, value); }
&&&&&&& // Using a DependencyProperty as the backing store for School.& This enables animation, styling, binding, etc...
&&&&&&& public static readonly DependencyProperty SchoolProperty =
&&&&&&&&&&& DependencyProperty.Register(&School&, typeof(string), typeof(Student), new UIPropertyMetadata(&&));如何理解WPF中的依赖项属性_百度知道
如何理解WPF中的依赖项属性
我有更好的答案
我的理解就是他绑在控件上,他变化,,控件就跟着变化
为您推荐:
其他类似问题
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。}

我要回帖

更多关于 wpf 依赖属性 绑定 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信