Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WPF依赖项属性和InotifyChanged属性_Wpf - Fatal编程技术网

WPF依赖项属性和InotifyChanged属性

WPF依赖项属性和InotifyChanged属性,wpf,Wpf,在实际场景中,使用/创建依赖项属性的实际用途是什么 如果我们使用通知,那么我将选择InotifyChanged属性 我从未在实时项目中看到/使用过依赖性属性的实际使用 有人能告诉我在实时场景中哪里需要DP吗?如果您创建了一个自定义控件,其属性希望是可绑定的(例如下面的代码),那么您不能使用INotifyPropertyChanged,并且必须使用DependencyProperty 假设您有这样一个UserControl: public partial class MyUserControl :

在实际场景中,使用/创建依赖项属性的实际用途是什么

如果我们使用通知,那么我将选择InotifyChanged属性

我从未在实时项目中看到/使用过依赖性属性的实际使用


有人能告诉我在实时场景中哪里需要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
    是绑定的

  • T
    仅允许是从属属性。e、 g:

    MyDependencyProperty=“{Binding something}”

  • S
    通常是一个INPC属性。e、 g:

    something=“{Binding MyINPCProperty}”


如果您创建了一个自定义控件,并且该控件的属性希望是可绑定的(例如,以下代码),则不能使用
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
    是绑定的

  • T
    仅允许是从属属性。e、 g:

    MyDependencyProperty=“{Binding something}”

  • S
    通常是一个INPC属性。e、 g:

    something=“{Binding MyINPCProperty}”


如果您创建了一个自定义控件,并且该控件的属性希望是可绑定的(例如,以下代码),则不能使用
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
    是绑定的

  • T
    仅允许是从属属性。e、 g:

    MyDependencyProperty=“{Binding something}”

  • S
    通常是一个INPC属性。e、 g:

    something=“{Binding MyINPCProperty}”


如果您创建了一个自定义控件,并且该控件的属性希望是可绑定的(例如,以下代码),则不能使用
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
    是绑定的

  • T
    仅允许是从属属性。e、 g:

    MyDependencyProperty=“{Binding something}”

  • S
    通常是一个INPC属性。e、 g:

    something=“{Binding MyINPCProperty}”

来自:

依赖属性的目的是提供一种计算 基于其他输入值的属性值。这些 其他输入可能包括系统属性,如主题和用户 首选项、即时属性确定机制,如 数据绑定和动画/故事板,多用途模板,如 作为资源和样式,或通过父子关系已知的值 与元素树中其他元素的关系。此外, 可以实现dependency属性以提供自包含的 验证、默认值、监视其他更改的回调 属性,以及可以基于 潜在的运行时信息。派生类也可以更改某些 通过重写现有属性的特定特征 依赖项属性元数据,而不是重写实际 实现现有属性或创建新属性

发件人:

依赖属性的目的是提供一种计算 基于其他输入值的属性值。这些 其他输入可能包括系统属性,如主题和用户 首选项、即时属性确定机制,如 数据绑定和动画/故事板,多用途模板,如 作为资源和样式,或通过父子关系已知的值 与元素树中其他元素的关系。此外, 可以实现dependency属性以提供自包含的 验证、默认值、监视其他更改的回调 属性,以及可以基于 潜在的运行时信息。派生类也可以更改某些 通过重写现有属性的特定特征 依赖项属性元数据,而不是重写实际 实现现有属性或创建新属性

发件人:

依赖属性的目的是提供一种计算 基于其他输入值的属性值。这些 其他输入可能包括系统属性,如主题和用户 首选项、即时属性确定机制,如 数据绑定