<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Sometimes you just gotta do the best you can [Tip: Read-only custom DependencyProperties don't exist in Silverlight, but can be closely approximated]</title><link>http://blogs.msdn.com/b/delay/archive/2010/03/30/sometimes-you-just-gotta-do-the-best-you-can-tip-read-only-custom-dependencyproperties-don-t-exist-in-silverlight-but-can-be-closely-approximated.aspx</link><description>Tip 
 Read-only custom DependencyProperties don't exist in Silverlight, but can be closely approximated 
 Explanation 
 My last tip discussed a special case of creating a Silverlight/WPF DependencyProperty where it's necessary to create a read-only</description><dc:language>en</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Sometimes you just gotta do the best you can [Tip: Read-only custom DependencyProperties don't exist in Silverlight, but can be closely approximated]</title><link>http://blogs.msdn.com/b/delay/archive/2010/03/30/sometimes-you-just-gotta-do-the-best-you-can-tip-read-only-custom-dependencyproperties-don-t-exist-in-silverlight-but-can-be-closely-approximated.aspx#10260390</link><pubDate>Wed, 25 Jan 2012 03:30:07 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10260390</guid><dc:creator>Shimmy Weitzhandler</dc:creator><description>&lt;p&gt;Won&amp;#39;t work on attached DPs though&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10260390" width="1" height="1"&gt;</description></item><item><title>re: Sometimes you just gotta do the best you can [Tip: Read-only custom DependencyProperties don't exist in Silverlight, but can be closely approximated]</title><link>http://blogs.msdn.com/b/delay/archive/2010/03/30/sometimes-you-just-gotta-do-the-best-you-can-tip-read-only-custom-dependencyproperties-don-t-exist-in-silverlight-but-can-be-closely-approximated.aspx#10157117</link><pubDate>Fri, 22 Apr 2011 15:24:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10157117</guid><dc:creator>wekempf</dc:creator><description>&lt;p&gt;DrWPF, as usual your suggestion is simple and functional. However, there&amp;#39;s a minor hole. This solution won&amp;#39;t work for readonly _attached_ properties. Honestly, most of my readonly DPs are attached DPs.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10157117" width="1" height="1"&gt;</description></item><item><title>re: Sometimes you just gotta do the best you can [Tip: Read-only custom DependencyProperties don't exist in Silverlight, but can be closely approximated]</title><link>http://blogs.msdn.com/b/delay/archive/2010/03/30/sometimes-you-just-gotta-do-the-best-you-can-tip-read-only-custom-dependencyproperties-don-t-exist-in-silverlight-but-can-be-closely-approximated.aspx#10090416</link><pubDate>Fri, 12 Nov 2010 23:39:05 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10090416</guid><dc:creator>David Anson</dc:creator><description>&lt;p&gt;jariza,&lt;/p&gt;
&lt;p&gt;That&amp;#39;s a great point, thanks for bringing it up! On the other hand, you might consider having a dedicated instance of the _changingMyReadOnly/_restoringMyReadOnly variables for each read-only DependencyProperty in a class so they&amp;#39;re all truly independent. Without analyzing it too much, I feel like this latter approach might be a bit easier to get right and more straightforward to think about.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10090416" width="1" height="1"&gt;</description></item><item><title>re: Sometimes you just gotta do the best you can [Tip: Read-only custom DependencyProperties don't exist in Silverlight, but can be closely approximated]</title><link>http://blogs.msdn.com/b/delay/archive/2010/03/30/sometimes-you-just-gotta-do-the-best-you-can-tip-read-only-custom-dependencyproperties-don-t-exist-in-silverlight-but-can-be-closely-approximated.aspx#10090368</link><pubDate>Fri, 12 Nov 2010 20:48:25 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10090368</guid><dc:creator>jariza</dc:creator><description>&lt;p&gt;Wouldn&amp;#39;t that be a problem if you have several read-only properties in the same class? You might want to set other properties when one of them changes, so I would add &lt;/p&gt;
&lt;p&gt; _changingMyReadOnly = false;&lt;/p&gt;
&lt;p&gt;right before&lt;/p&gt;
&lt;p&gt;myControl.OnMyReadOnlyChanged((int)e.OldValue, (int)e.NewValue);&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10090368" width="1" height="1"&gt;</description></item><item><title>re: Sometimes you just gotta do the best you can [Tip: Read-only custom DependencyProperties don't exist in Silverlight, but can be closely approximated]</title><link>http://blogs.msdn.com/b/delay/archive/2010/03/30/sometimes-you-just-gotta-do-the-best-you-can-tip-read-only-custom-dependencyproperties-don-t-exist-in-silverlight-but-can-be-closely-approximated.aspx#9989034</link><pubDate>Thu, 01 Apr 2010 18:12:06 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9989034</guid><dc:creator>DrWPF</dc:creator><description>&lt;p&gt;The biggest issue I see with your solution, SharpGIS, is that it does not create a readonly DP. &amp;nbsp;Your approach only makes it more difficult to modify the value, but its not a true readonly property. &amp;nbsp;For example, you can change the value of the DP by creating a two-way binding to the property and changing the bound value (e.g., bind the Text property of a TextBox to your property using a TwoWay binding and then change the text in the control and it will update your property).&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9989034" width="1" height="1"&gt;</description></item><item><title>re: Sometimes you just gotta do the best you can [Tip: Read-only custom DependencyProperties don't exist in Silverlight, but can be closely approximated]</title><link>http://blogs.msdn.com/b/delay/archive/2010/03/30/sometimes-you-just-gotta-do-the-best-you-can-tip-read-only-custom-dependencyproperties-don-t-exist-in-silverlight-but-can-be-closely-approximated.aspx#9988416</link><pubDate>Wed, 31 Mar 2010 22:08:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9988416</guid><dc:creator>David Anson</dc:creator><description>&lt;p&gt;SharpGIS,&lt;/p&gt;
&lt;p&gt;Your InternalsVisibleTo solution excites and revolts me - at the same time. :) I'll be doing a follow-up blog post to this one and I'll include your suggestion along with DrWPF's.&lt;/p&gt;
&lt;p&gt;Thanks very much for sharing!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9988416" width="1" height="1"&gt;</description></item><item><title>re: Sometimes you just gotta do the best you can [Tip: Read-only custom DependencyProperties don't exist in Silverlight, but can be closely approximated]</title><link>http://blogs.msdn.com/b/delay/archive/2010/03/30/sometimes-you-just-gotta-do-the-best-you-can-tip-read-only-custom-dependencyproperties-don-t-exist-in-silverlight-but-can-be-closely-approximated.aspx#9988337</link><pubDate>Wed, 31 Mar 2010 20:09:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9988337</guid><dc:creator>David Anson</dc:creator><description>&lt;p&gt;SharpGIS,&lt;/p&gt;
&lt;p&gt;I'm saying that WPF will not allow &amp;quot;SetValue(MyReadOnlyProperty, 5)&amp;quot; to succeed on a read-only DependencyProperty (you need to use the private DependencyPropertyKey instead) and therefore that the same code should not work for &amp;quot;simulated read-only&amp;quot; properties on Silverlight, either.&lt;/p&gt;
&lt;p&gt;Regarding your InternalsVisibleTo suggestion, I've Twittered you just now to discuss this further. I'll post a follow-up comment here after we've come to an agreement. :)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9988337" width="1" height="1"&gt;</description></item><item><title>re: Sometimes you just gotta do the best you can [Tip: Read-only custom DependencyProperties don't exist in Silverlight, but can be closely approximated]</title><link>http://blogs.msdn.com/b/delay/archive/2010/03/30/sometimes-you-just-gotta-do-the-best-you-can-tip-read-only-custom-dependencyproperties-don-t-exist-in-silverlight-but-can-be-closely-approximated.aspx#9988331</link><pubDate>Wed, 31 Mar 2010 19:57:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9988331</guid><dc:creator>Morten Nielsen</dc:creator><description>&lt;p&gt;btw are you now saying that it's &amp;quot;illegal&amp;quot; to do this:&lt;/p&gt;
&lt;p&gt;myObject.SetValue(MyReadOnlyProperty,5) ?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9988331" width="1" height="1"&gt;</description></item><item><title>re: Sometimes you just gotta do the best you can [Tip: Read-only custom DependencyProperties don't exist in Silverlight, but can be closely approximated]</title><link>http://blogs.msdn.com/b/delay/archive/2010/03/30/sometimes-you-just-gotta-do-the-best-you-can-tip-read-only-custom-dependencyproperties-don-t-exist-in-silverlight-but-can-be-closely-approximated.aspx#9988327</link><pubDate>Wed, 31 Mar 2010 19:51:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9988327</guid><dc:creator>Morten Nielsen</dc:creator><description>&lt;p&gt;There's a MUCH easier way:&lt;/p&gt;
&lt;p&gt;[assembly: InternalsVisibleTo(&amp;quot;System.Windows, PublicKey=00240000048000009400000006020000002400005253413100040000010001008d56c76f9e8649383049f383c44be0ec204181822a6c31cf5eb7ef486944d032188ea1d3920763712ccb12d75fb77e9811149e6148e5d32fbaab37611c1878ddc19e20ef135d0cb2cff2bfec3d115810c3d9069638fe4be215dbf795861920e5ab6f7db2e2ceef136ac23d5dd2bf031700aec232f6c6b1c785b4305c123b37ab&amp;quot;)]&lt;/p&gt;
&lt;p&gt;public int MyReadOnly&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;get { return (int)GetValue(MyReadOnlyProperty); }&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;private set&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SetValue(MyReadOnlyProperty, value);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;internal static readonly DependencyProperty MyReadOnlyProperty = DependencyProperty.Register(&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;&amp;quot;MyReadOnly&amp;quot;, typeof(int), typeof(MyControl), new PropertyMetadata(0));&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9988327" width="1" height="1"&gt;</description></item><item><title>re: Sometimes you just gotta do the best you can [Tip: Read-only custom DependencyProperties don't exist in Silverlight, but can be closely approximated]</title><link>http://blogs.msdn.com/b/delay/archive/2010/03/30/sometimes-you-just-gotta-do-the-best-you-can-tip-read-only-custom-dependencyproperties-don-t-exist-in-silverlight-but-can-be-closely-approximated.aspx#9988245</link><pubDate>Wed, 31 Mar 2010 17:04:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9988245</guid><dc:creator>David Anson</dc:creator><description>&lt;p&gt;DrWPF,&lt;/p&gt;
&lt;p&gt;Wow, that is a great suggestion! I'm emailing you now to discuss a couple of things about it, but once that's settled, it sounds like I need another DependencyProperty tip to discuss your solution.&lt;/p&gt;
&lt;p&gt;Thanks very much!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9988245" width="1" height="1"&gt;</description></item></channel></rss>