<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: WPF: Setting a Type Specific Property Value</title>
	<atom:link href="http://mel-green.com/2009/08/wpf-setting-a-type-specific-property-value/feed/" rel="self" type="application/rss+xml" />
	<link>http://mel-green.com/2009/08/wpf-setting-a-type-specific-property-value/</link>
	<description></description>
	<lastBuildDate>Wed, 25 Jan 2012 16:43:42 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Mel</title>
		<link>http://mel-green.com/2009/08/wpf-setting-a-type-specific-property-value/comment-page-1/#comment-1639</link>
		<dc:creator>Mel</dc:creator>
		<pubDate>Thu, 12 Jan 2012 16:55:51 +0000</pubDate>
		<guid isPermaLink="false">http://mel-green.com/?p=360#comment-1639</guid>
		<description>Hey ADTC, 

Thanks for the comment, all good points! In .Net any string can easily be parsed into a value of a different data type. However I believe I was trying to illustrate defining data types strictly in XAML (I was on a big XAML kick back then), although both my example and solution were overly simple and kind of useless really, as solutions such as your&#039;s and Roland&#039;s below are much smarter. :)</description>
		<content:encoded><![CDATA[<p>Hey ADTC, </p>
<p>Thanks for the comment, all good points! In .Net any string can easily be parsed into a value of a different data type. However I believe I was trying to illustrate defining data types strictly in XAML (I was on a big XAML kick back then), although both my example and solution were overly simple and kind of useless really, as solutions such as your&#8217;s and Roland&#8217;s below are much smarter. <img src='http://mel-green.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ADTC</title>
		<link>http://mel-green.com/2009/08/wpf-setting-a-type-specific-property-value/comment-page-1/#comment-1636</link>
		<dc:creator>ADTC</dc:creator>
		<pubDate>Thu, 12 Jan 2012 01:19:06 +0000</pubDate>
		<guid isPermaLink="false">http://mel-green.com/?p=360#comment-1636</guid>
		<description>For your original problem where you have &lt;strong&gt;Tag=&quot;True&quot;&lt;/strong&gt; and getting &lt;strong&gt;sourceBtn.Tag&lt;/strong&gt; gives you a string, just parse the string into a boolean using &lt;strong&gt;Boolean.Parse(...)&lt;/strong&gt;, like this:


&lt;pre&gt;bool isRight = Boolean.Parse(sourceBtn.Tag);&lt;/pre&gt;

Of course, if you are not sure that &lt;strong&gt;sourceBtn.Tag&lt;/strong&gt; will always be either True or False, you should either do the parsing in a try/catch, or use &lt;strong&gt;Boolean.TryParse(...)&lt;/strong&gt; like this:


&lt;pre&gt;&lt;strong&gt;bool isRight; Boolean.TryParse(sourceBtn.Tag, out isRight);&lt;/strong&gt;&lt;/pre&gt;
That should do :)</description>
		<content:encoded><![CDATA[<p>For your original problem where you have <strong>Tag=&#8221;True&#8221;</strong> and getting <strong>sourceBtn.Tag</strong> gives you a string, just parse the string into a boolean using <strong>Boolean.Parse(&#8230;)</strong>, like this:</p>
<pre>bool isRight = Boolean.Parse(sourceBtn.Tag);</pre>
<p>Of course, if you are not sure that <strong>sourceBtn.Tag</strong> will always be either True or False, you should either do the parsing in a try/catch, or use <strong>Boolean.TryParse(&#8230;)</strong> like this:</p>
<pre><strong>bool isRight; Boolean.TryParse(sourceBtn.Tag, out isRight);</strong></pre>
<p>That should do <img src='http://mel-green.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mel</title>
		<link>http://mel-green.com/2009/08/wpf-setting-a-type-specific-property-value/comment-page-1/#comment-81</link>
		<dc:creator>Mel</dc:creator>
		<pubDate>Fri, 07 Aug 2009 22:33:26 +0000</pubDate>
		<guid isPermaLink="false">http://mel-green.com/?p=360#comment-81</guid>
		<description>&lt;p&gt;Hey Roland,&lt;/p&gt;
&lt;p&gt;Thanks for the feedback!&lt;/p&gt;
&lt;p&gt;I didn&#039;t know anything about attached properties until you mentioned them, thus triggering some research on my part. I think they would work better!&lt;/p&gt;
&lt;p&gt;When I get a chance I&#039;ll write a follow up post to this one that illustrates the superior method you described.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Mel&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>Hey Roland,</p>
<p>Thanks for the feedback!</p>
<p>I didn&#8217;t know anything about attached properties until you mentioned them, thus triggering some research on my part. I think they would work better!</p>
<p>When I get a chance I&#8217;ll write a follow up post to this one that illustrates the superior method you described.</p>
<p>Thanks,</p>
<p>Mel</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Roland Tomczak</title>
		<link>http://mel-green.com/2009/08/wpf-setting-a-type-specific-property-value/comment-page-1/#comment-80</link>
		<dc:creator>Roland Tomczak</dc:creator>
		<pubDate>Fri, 07 Aug 2009 20:54:53 +0000</pubDate>
		<guid isPermaLink="false">http://mel-green.com/?p=360#comment-80</guid>
		<description>Hi,

You should perhaps make use of a stronlgy-type attached property.. For example, if your button is in a UserControl &#039;ButtonGame&quot;, define an attached property of this UserControl.. Once done, you could write something like &quot;&quot;.

This would be cleaner than this &quot;tag&quot; thing. 

But the cleanest way would probably to have an associated datamodel, for example using the well-known MVVM design pattern.

Regards,

Roland Tomczak</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>You should perhaps make use of a stronlgy-type attached property.. For example, if your button is in a UserControl &#8216;ButtonGame&#8221;, define an attached property of this UserControl.. Once done, you could write something like &#8220;&#8221;.</p>
<p>This would be cleaner than this &#8220;tag&#8221; thing. </p>
<p>But the cleanest way would probably to have an associated datamodel, for example using the well-known MVVM design pattern.</p>
<p>Regards,</p>
<p>Roland Tomczak</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic page generated in 0.963 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-02-02 13:09:57 -->

