Recommended

Skip Navigation LinksHome / Search

Search

 
Results Per Page

Found 6 results for DependencyProperty.
Date between: <not defined> and <not defined>
Search in: News , Articles , Tips , Shows , Showcase , Books

Order by Publish Date   Ascending Title   Rating  

  • 0 comments  /  posted by  Silverlight Show  on  Mar 29, 2010 (2 months ago)
    David Anson has another tip for using DependencyProperty.

    In the previous tip, I explained why it's usually wrong to assign a value to a Silverlight/WPF DependencyProperty in the constructor for a class. The preferred way is to pass the default value in the call to Register, but there's another good option: set the property's starting value in the default Style for the control by putting it in generic.xaml.



  • Tip: When creating a DependencyProperty, follow the handy convention of "wrapper+register+static+virtual"

    0 comments  /  posted by  Silverlight Show  on  Mar 25, 2010 (2 months ago)
    David Anson has a quick tip for those of you who need to create a DependencyProperty.

    The fundamental steps for defining a Silverlight/WPF DependencyProperty are fairly rigid and not open to a great deal of flexibility (as I discuss in this earlier tip about the CLR wrapper). However, there's a bit more freedom once you add a default value or a PropertyChangedCallback delegate to the mix - but don't let it go to your head!

  • Declarative Dependency Property Definition with T4 + DTE

    0 comments  /  posted by  Ilia Iordanov  on  Aug 18, 2009 (10 months ago)
    Tags: Colin Eberhardt , declarative , dependency property , T4 + DTE

    Colin Eberhardt’s is talking about using declarative dependency property definition with T4 + DTE. A lot of explanation and source code, you should check it.

    A few months ago I wrote an article on codeproject about a technique for generating dependency properties via T4 templates. In brief; with this technique, you provide an XML description of your classes and their dependency properties, run the T4 template, and partial classes are generated which contain these properties – no more writing DP boiler plate code! For those of you who are unfamiliar with T4, it is a code generation engine which is built into Visual Studio, for a primer, I refer you to my codeproject article.

  • Silverlight Dependency Property Snippets

    0 comments  /  posted by  Silverlight Show  on  Mar 10, 2009 (more than a year ago)
    Tags: Dependency Property , Snippets

    Shawn Wildermuth has posted a Silverlight Dependency Property snippet. Cameron Albert also has created such a snippet. Both of the posts deserve your attention.

  • Dependency Property Generator for Silverlight

    0 comments  /  posted by  Silverlight Show  on  Mar 10, 2009 (more than a year ago)
    Tags: Dependency Property

    Kirupa Chinnathambi has built up a dependency property generator for Silverlight.

    Ever since I wrote an article describing dependency properties, many people have been asking me to help debug their dependency property issue. In majority of the cases, the problems were related to the C# equivalent of forgetting to dot an i or cross a t.

  • 3 comments  /  posted by  Ilia Iordanov  on  Sep 09, 2008 (more than a year ago)

    Probably the first most important thing to mention here is that only inheritors of System.Windows.DependencyObject can be extended with dependency properties. This is needed because either to set or to get value for a specific dependency property, you need to use the methods SetValue and GetValue which are defined in the DependencyObject class.
    When you declare a dependency property, many advantages are coming out of the box for you such as caching, data binding, default values, expressions, styling, property invalidation and more.

    In order to declare a dependency property in Silverlight, you have to follow few simple steps as explained in the sample code below.

    C#

    public partial class MySilverlightControl : UserControl
    {
        //1. Declare the dependency property as static, readonly field in your class.
        public static readonly DependencyProperty MyPropertyProperty = DependencyProperty.Register(
            "MyProperty",                               //Property name
            typeof( string ),                           //Property type
            typeof( MySilverlightControl ),             //Type of the dependency property provider
            new PropertyMetadata( MyPropertyChanged ) );//Callback invoked on property value has changes
     
        public MySilverlightControl()
        {
            InitializeComponent();
        }
     
        //2. Create the property and use the SetValue/GetValue methods of the DependencyObject class
        public string MyProperty
        {
            set
            {
                this.SetValue( MyPropertyProperty, value );
            }
            get
            {
                return ( string )this.GetValue( MyPropertyProperty );
            }
        }
     
        private static void MyPropertyChanged( object sender, DependencyPropertyChangedEventArgs args )
        {
            //Do some processing here...
        }
    }

    Read more about DependencyObject and DependencyProperty classes on MSDN.

    That's it!


Help us make SilverlightShow even better and win a free t-shirt. Whether you'd like to suggest a change in the structure, content organization, section layout or any other aspect of SilverlightShow appearance - we'd love to hear from you! Need a material (article, tutorial, or other) on a specific topic? Let us know and SilverlightShow content authors will work to have that prepared for you. (hide this)