WPF依赖项属性和InotifyChanged属性
在实际场景中,使用/创建依赖项属性的实际用途是什么 如果我们使用通知,那么我将选择InotifyChanged属性 我从未在实时项目中看到/使用过依赖性属性的实际使用WPF依赖项属性和InotifyChanged属性,wpf,Wpf,在实际场景中,使用/创建依赖项属性的实际用途是什么 如果我们使用通知,那么我将选择InotifyChanged属性 我从未在实时项目中看到/使用过依赖性属性的实际使用 有人能告诉我在实时场景中哪里需要DP吗?如果您创建了一个自定义控件,其属性希望是可绑定的(例如下面的代码),那么您不能使用INotifyPropertyChanged,并且必须使用DependencyProperty 假设您有这样一个UserControl: public partial class MyUserControl :
有人能告诉我在实时场景中哪里需要DP吗?如果您创建了一个自定义控件,其属性希望是可绑定的(例如下面的代码),那么您不能使用
INotifyPropertyChanged
,并且必须使用DependencyProperty
假设您有这样一个UserControl
:
public partial class MyUserControl : UserControl
{
public List<ItemViewModel> ItemsSource
{
get { return (List<ItemViewModel>)GetValue(ItemsSourceProperty); }
set { SetValue(ItemsSourceProperty, value); }
}
// Using a DependencyProperty as the backing store for ItemsSource. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ItemsSourceProperty =
DependencyProperty.Register("ItemsSource", typeof(List<ItemViewModel>), typeof(MyUserControl ), new PropertyMetadata(null));
}
作为摘要:
一般来说,绑定是这样的:T=“{binding S}”
是绑定的目标T
是绑定的源S
仅允许是从属属性。e、 g: MyDependencyProperty=“{Binding something}”T
通常是一个INPC属性。e、 g: something=“{Binding MyINPCProperty}”S
INotifyPropertyChanged
,并且必须使用DependencyProperty
假设您有这样一个UserControl
:
public partial class MyUserControl : UserControl
{
public List<ItemViewModel> ItemsSource
{
get { return (List<ItemViewModel>)GetValue(ItemsSourceProperty); }
set { SetValue(ItemsSourceProperty, value); }
}
// Using a DependencyProperty as the backing store for ItemsSource. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ItemsSourceProperty =
DependencyProperty.Register("ItemsSource", typeof(List<ItemViewModel>), typeof(MyUserControl ), new PropertyMetadata(null));
}
作为摘要:
一般来说,绑定是这样的:T=“{binding S}”
是绑定的目标T
是绑定的源S
仅允许是从属属性。e、 g: MyDependencyProperty=“{Binding something}”T
通常是一个INPC属性。e、 g: something=“{Binding MyINPCProperty}”S
INotifyPropertyChanged
,并且必须使用DependencyProperty
假设您有这样一个UserControl
:
public partial class MyUserControl : UserControl
{
public List<ItemViewModel> ItemsSource
{
get { return (List<ItemViewModel>)GetValue(ItemsSourceProperty); }
set { SetValue(ItemsSourceProperty, value); }
}
// Using a DependencyProperty as the backing store for ItemsSource. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ItemsSourceProperty =
DependencyProperty.Register("ItemsSource", typeof(List<ItemViewModel>), typeof(MyUserControl ), new PropertyMetadata(null));
}
作为摘要:
一般来说,绑定是这样的:T=“{binding S}”
是绑定的目标T
是绑定的源S
仅允许是从属属性。e、 g: MyDependencyProperty=“{Binding something}”T
通常是一个INPC属性。e、 g: something=“{Binding MyINPCProperty}”S
INotifyPropertyChanged
,并且必须使用DependencyProperty
假设您有这样一个UserControl
:
public partial class MyUserControl : UserControl
{
public List<ItemViewModel> ItemsSource
{
get { return (List<ItemViewModel>)GetValue(ItemsSourceProperty); }
set { SetValue(ItemsSourceProperty, value); }
}
// Using a DependencyProperty as the backing store for ItemsSource. This enables animation, styling, binding, etc...
public static readonly DependencyProperty ItemsSourceProperty =
DependencyProperty.Register("ItemsSource", typeof(List<ItemViewModel>), typeof(MyUserControl ), new PropertyMetadata(null));
}
作为摘要:
一般来说,绑定是这样的:T=“{binding S}”
是绑定的目标T
是绑定的源S
仅允许是从属属性。e、 g: MyDependencyProperty=“{Binding something}”T
通常是一个INPC属性。e、 g: something=“{Binding MyINPCProperty}”S