publicint MyProperty { get { return (int)GetValue(MyPropertyProperty); } set { SetValue(MyPropertyProperty, value); } }
// Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc... publicstaticreadonly DependencyProperty MyPropertyProperty = DependencyProperty.Register("MyProperty", typeof(int), typeof(ownerclass), new PropertyMetadata(0));
Property(屬性)
主要用在CodeBehind,xaml沒辦法用自訂的屬性Property
1 2 3 4 5 6 7 8 9 10 11 12 13
privatebool _DefaultPropertyName; publicbool DefaultPropertyName { get { return _DefaultPropertyName; } set { _DefaultPropertyName = value; OnPropertyChanged(); } }
Property跟Dependency Property之間溝通
1 2 3 4
//取得資料 : var data = (DataType)GetValue(DependencyPropertyName); //設定資料 : SetValue(DependencyPropertyName, value);