SilverlightShow: Tip: How to declare a dependency property in Silverlight? Comments http://www.silverlightshow.net/ Silverlight articles, Silverlight tutorials, Silverlight videos, Silverlight samples SilverlightShow.net http://www.rssboard.org/rss-specification Argotic Syndication Framework 2008.0.2.0, http://www.codeplex.com/Argotic en-US estoychev@completit.com (Emil Stoychev) Re: Tip: How to declare a dependency property in Silverlight? <p>To access this dependecy preperty you have to first acces to the namespace throught the xaml code:</p> <p>  xmlns:Controls="clr-namespace:YourProjcet.NameSpaceWhereYouDeclaredYourControl"    </p> <p>and then simply call your user control:</p> <p><Controls:YourControl   YourDependencyProperty={ you can even bind to a property} /></p> http://www.silverlightshow.net/items/Tip-How-to-declare-a-dependancy-property-in-Silverlight.aspx#comment6620 TemalaRidha http://www.silverlightshow.net/items/Tip-How-to-declare-a-dependancy-property-in-Silverlight.aspx Mon, 10 Oct 2011 11:39:40 GMT RE: Tip: How to declare a dependency property in Silverlight? <p>Hi All,</p> <p> Ofter declare the DP. how can access the same control in my a XAML design please let me know .</p> <p>  </p> http://www.silverlightshow.net/items/Tip-How-to-declare-a-dependancy-property-in-Silverlight.aspx#comment5579 Narasimha http://www.silverlightshow.net/items/Tip-How-to-declare-a-dependancy-property-in-Silverlight.aspx Fri, 25 Feb 2011 08:27:36 GMT RE: Tip: How to declare a dependency property in Silverlight? Hey, thanks for this resource! http://www.silverlightshow.net/items/Tip-How-to-declare-a-dependancy-property-in-Silverlight.aspx#comment4001 Andy Bruce http://www.silverlightshow.net/items/Tip-How-to-declare-a-dependancy-property-in-Silverlight.aspx Sat, 17 Jul 2010 23:42:38 GMT RE: Tip: How to declare a dependency property in Silverlight? <span style="font-family: verdana; font-size: 11px; "><p>Below is an example.</p><p>The default value and the propertychanged handler are optional. Depends on whether you want something besides null as the default value if the setter is never called, and whether you want to execute some code when the value changes. Note that the naming of properties are important. Search/Replace "MyProperty" with whatever you want to call it, but not that the stafic DP must be names [name]Property.</p><pre class="coloredcode"><span class="kwd" style="color: rgb(0, 0, 255); ">public</span> MyObjectType MyProperty<br />{<br /> <span class="kwd" style="color: rgb(0, 0, 255); ">get</span> { <span class="kwd" style="color: rgb(0, 0, 255); ">return</span> (MyObjectType)GetValue(MyPropertyProperty); }<br /> <span class="kwd" style="color: rgb(0, 0, 255); ">set</span> { SetValue(MyPropertyProperty, <span class="kwd" style="color: rgb(0, 0, 255); ">value</span>); } <span class="cmt" style="color: rgb(0, 213, 2); ">//Never put code here! Put it in onMyPropertyChanged</span><br />}<br /><br /><span class="kwd" style="color: rgb(0, 0, 255); ">public static readonly</span> DependencyProperty MyPropertyProperty =<br /> DependencyProperty.Register(<span class="st" style="color: rgb(255, 0, 0); ">"MyProperty"</span>, <span class="kwd" style="color: rgb(0, 0, 255); ">typeof</span>(MyObjectType), <span class="kwd" style="color: rgb(0, 0, 255); ">typeof</span>(MyControl), <span class="kwd" style="color: rgb(0, 0, 255); ">new</span> PropertyMetadata([DefaultValue], onMyPropertyChanged));<br /><br /><span class="kwd" style="color: rgb(0, 0, 255); ">private static void</span> onMyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)<br />{<br /> MyControl obj = d <span class="kwd" style="color: rgb(0, 0, 255); ">as</span> MyControl;<br /> <span class="cmt" style="color: rgb(0, 213, 2); ">//handle changed values</span><br />}</pre><p>Next step is to create a Control with a Template. You can then bind this value into your control using:</p><p><TextBox Text="{TemplateBinding MyProperty}" /> </p><p>You might want to see this post on how to create your own custom controls: http://www.silverlightshow.net/items/Creating-a-Silverlight-Custom-Control-The-Basics.aspx</p></span> http://www.silverlightshow.net/items/Tip-How-to-declare-a-dependancy-property-in-Silverlight.aspx#comment2232 Nishanth http://www.silverlightshow.net/items/Tip-How-to-declare-a-dependancy-property-in-Silverlight.aspx Wed, 12 Aug 2009 13:46:29 GMT RE: Tip: How to declare a dependency property in Silverlight? so how do you make an property that expects an IEnumerable such as ItemsSource from a ComboBox, and what if you have two or more controls that you want to add a dependy property to make data-bindable?  For example, if I had two ComboBoxes in your example above, the MySilverLightControl, how do I specify which ComboBox a property belongs to? http://www.silverlightshow.net/items/Tip-How-to-declare-a-dependancy-property-in-Silverlight.aspx#comment1616 Hector http://www.silverlightshow.net/items/Tip-How-to-declare-a-dependancy-property-in-Silverlight.aspx Thu, 28 May 2009 11:54:12 GMT