Dependency Property in WPF / SilverLight

I searched on google about how to get started with the dependency property used in WPF / silverlight, but didn't understand the dependency property, could anyone tell me about this from a novice point of view, so I get some idea about this and I use it in my project

early.

Can someone give me a link or sample code for a simple application that explains in a simple way what a dependency property is ??? I'll be very grateful

+3
source share
5 answers

I find that the DependencyProperty implementation often includes four parts:

  • DependencyProperty itself
  • Property with get and set
  • Static Modified Handler

UserControl, DataContext, UserControl. , SoUserControl:

    #region SampleProperty // Demo for SO 2424526

    public static readonly DependencyProperty SamplePropertyProperty
        = DependencyProperty.Register("SampleProperty", typeof(int), typeof(SoUserControl), new PropertyMetadata(OnSamplePropertyChanged));


    /// <summary>
    /// Demo for SO 2424526
    /// Gets or sets dependency property.
    /// </summary>
    public int SampleProperty
    {
        get { return (int)GetValue(SamplePropertyProperty); }
        set { SetValue(SamplePropertyProperty, value); }
    }

    /// <summary>
    /// Handld changes to SamplePropertyProperty by calling a handler in the associated object.
    /// </summary>
    /// <param name="obj">object the property is associated with</param>
    /// <param name="e">details of change</param>
    static void OnSamplePropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
    {
        (obj as SoUserControl).OnSamplePropertyChanged(e);
    }

    /// <summary>
    /// Handle changes to the SamplePropertyProperty dependency property.
    /// </summary>
    /// <param name="e">details of change</param>
    private void OnSamplePropertyChanged(DependencyPropertyChangedEventArgs e)
    {
        int SamplePropertyNewValue = (int)e.NewValue;
        // do something with the internal logic of the control
    }

    #endregion
+7

. . , , , INotifyPropertyChanged NotifyPropertyChanged, Dependency INotifyProperty Changed.

- . , WPF, ... .

DepenedencyProperties , DependencyObject. UIElement Visual, DependencyObject, .Net- . DependencyProperties UserControls, UIElement.

, ( INotifyPropertyChanged )

: http://msdn.microsoft.com/en-us/library/ms752914.aspx, http://www.wpftutorial.net/DependencyProperties.html

+4
+1

, . . , , , .

. , , , . , "", - , - - , .

DependencyObject ( , , ).

, . , , .

, : http://blog.hackedbrain.com/2004/12/04/understanding-dependencyobject-and-dependencyproperty/

0

.

WPF Visual Sutdio 2005 Manning.

, , Dependency Property , WPF, .

, , , , , .

, - MSDN WPF Property Dependency.

-4

Source: https://habr.com/ru/post/1736476/


All Articles