<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.silverlight.net/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>Programming with .NET - General</title><link>http://forums.silverlight.net/forums/17.aspx</link><description>General discussions around authoring Silverlight .NET applications.</description><dc:language>en</dc:language><generator>CommunityServer 2007 (Build: 20416.853)</generator><item><title>Re: Enum as DepedencyProperty</title><link>http://forums.silverlight.net/forums/thread/302563.aspx</link><pubDate>Wed, 14 Oct 2009 10:08:19 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:302563</guid><dc:creator>rankorn</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/302563.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=17&amp;PostID=302563</wfw:commentRss><description>In SL3, you do not even have to use TypeConverter as it automatically handles enums.

I am not sure about intellisense.</description></item><item><title>Re: Enum as DepedencyProperty</title><link>http://forums.silverlight.net/forums/thread/211561.aspx</link><pubDate>Fri, 24 Apr 2009 16:49:15 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:211561</guid><dc:creator>DJanjicek</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/211561.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=17&amp;PostID=211561</wfw:commentRss><description>&lt;p&gt;It works! Still a pity that IntelliSense doesn&amp;#39;t work...&lt;/p&gt;
&lt;p&gt;Anyways, thank you!&lt;/p&gt;</description></item><item><title>Re: Enum as DepedencyProperty</title><link>http://forums.silverlight.net/forums/thread/211554.aspx</link><pubDate>Fri, 24 Apr 2009 16:30:39 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:211554</guid><dc:creator>DMW</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/211554.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=17&amp;PostID=211554</wfw:commentRss><description>No, absolutely not.

You can expose a single DP, whose type is the type of the enum. Then you will be able to set the value of that property to any of the values of the enum.</description></item><item><title>Re: Enum as DepedencyProperty</title><link>http://forums.silverlight.net/forums/thread/211532.aspx</link><pubDate>Fri, 24 Apr 2009 15:53:14 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:211532</guid><dc:creator>DJanjicek</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/211532.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=17&amp;PostID=211532</wfw:commentRss><description>&lt;p&gt;Okay, so i have to create for every enum value a property?&lt;/p&gt;</description></item><item><title>Re: Enum as DepedencyProperty</title><link>http://forums.silverlight.net/forums/thread/211363.aspx</link><pubDate>Fri, 24 Apr 2009 09:06:34 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:211363</guid><dc:creator>DMW</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/211363.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=17&amp;PostID=211363</wfw:commentRss><description>In the call to DependencyProperty.Register, make sure that the last parameter reads something like this

new PropertyMetadata( Foo.A )

assuming that you have an enum called Foo, with a named value A.</description></item><item><title>Re: Enum as DepedencyProperty</title><link>http://forums.silverlight.net/forums/thread/211309.aspx</link><pubDate>Fri, 24 Apr 2009 06:33:41 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:211309</guid><dc:creator>DJanjicek</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/211309.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=17&amp;PostID=211309</wfw:commentRss><description>&lt;p&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/silverlight/images/icon-quote.gif"&gt; &lt;strong&gt;dmw:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;A further thought has crossed my mind. A common mistake to make when registering DPs is to leave in the default PropertyMetadata(0) in the DP.Register method. This will result in a TypeInitializationException at runtime, and potentially strange problems at design-time. &lt;strong&gt;Make sure that you change this to a proper value of the enum, as the PropertyMetadata constructor takes a parameter of type object&lt;/strong&gt;. Thus boxing will occur, and unboxing an Int32 to an enum will fail during type initialization.&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t understand this one... Could you provide an example?&lt;/p&gt;</description></item><item><title>Re: Enum as DepedencyProperty</title><link>http://forums.silverlight.net/forums/thread/211236.aspx</link><pubDate>Fri, 24 Apr 2009 02:11:47 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:211236</guid><dc:creator>DMW</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/211236.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=17&amp;PostID=211236</wfw:commentRss><description>A further thought has crossed my mind.

A common mistake to make when registering DPs is to leave in the default PropertyMetadata(0) in the DP.Register method. This will result in a TypeInitializationException at runtime, and potentially strange problems at design-time.

Make sure that you change this to a proper value of the enum, as the PropertyMetadata constructor takes a parameter of type object. Thus boxing will occur, and unboxing an Int32 to an enum will fail during type initialization.</description></item><item><title>Re: Enum as DepedencyProperty</title><link>http://forums.silverlight.net/forums/thread/211235.aspx</link><pubDate>Fri, 24 Apr 2009 02:06:37 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:211235</guid><dc:creator>DMW</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/211235.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=17&amp;PostID=211235</wfw:commentRss><description>&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/silverlight/images/icon-quote.gif"&gt; &lt;strong&gt;DJanjicek:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;i doubt the MS guys have written a converter for every particular enum they&amp;#39;re using&lt;/div&gt;&lt;/BLOCKQUOTE&gt;

Your are quite correct; they have not.

The XAML parser can automatically parse strings to named enum values, and if you examine an enum-based property in Blend, you will see that it automatically displays a drop-down for the property.

You therefore do not need to use a TypeConverter, and doing so will achieve little for a simple enum. I&amp;#39;m not denying that you might have had problems, but a TypeConverter is not the solution to them.</description></item><item><title>Re: Enum as DepedencyProperty</title><link>http://forums.silverlight.net/forums/thread/211123.aspx</link><pubDate>Thu, 23 Apr 2009 20:09:23 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:211123</guid><dc:creator>DJanjicek</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/211123.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=17&amp;PostID=211123</wfw:commentRss><description>&lt;p&gt;I&amp;#39;ll post the c# version tomorrow! Thanks for your effort! &lt;img src="http://silverlight.net/emoticons/emotion-21.gif" alt="Yes" /&gt;&lt;/p&gt;</description></item><item><title>Re: Enum as DepedencyProperty</title><link>http://forums.silverlight.net/forums/thread/211119.aspx</link><pubDate>Thu, 23 Apr 2009 19:58:31 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:211119</guid><dc:creator>wjchristenson2</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/211119.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=17&amp;PostID=211119</wfw:commentRss><description>&lt;p&gt;Below is a generic EnumTypeConverter class i wrote.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Here&amp;#39;s a property using it:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;TypeConverter(&lt;span class="kwd"&gt;GetType&lt;/span&gt;(EnumTypeConverter(Of Vehicle.VehicleType)))&amp;gt; _&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwd"&gt;Public Property&lt;/span&gt; Type() &lt;span class="kwd"&gt;As&lt;/span&gt; VehicleType&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwd"&gt;Get&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return DirectCast&lt;/span&gt;(GetValue(Vehicle.TypeProperty), VehicleType)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwd"&gt;End Get&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set&lt;/span&gt;(&lt;span class="kwd"&gt;ByVal&lt;/span&gt; value &lt;span class="kwd"&gt;As&lt;/span&gt; VehicleType)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SetValue(Vehicle.TypeProperty, value)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwd"&gt;End Set&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End Property&lt;/span&gt; 
&lt;p&gt;&lt;strong&gt;Here is the generic&amp;nbsp;EnumTypeConverter:&lt;/strong&gt;&lt;/p&gt;&lt;pre class="coloredcode"&gt;&lt;span class="kwd"&gt;Imports&lt;/span&gt; System.ComponentModel

&lt;span class="kwd"&gt;Public Class&lt;/span&gt; EnumTypeConverter(Of T)
    &lt;span class="kwd"&gt;Inherits&lt;/span&gt; TypeConverter

    &lt;span class="kwd"&gt;Public Overrides Function&lt;/span&gt; CanConvertFrom(&lt;span class="kwd"&gt;ByVal&lt;/span&gt; context &lt;span class="kwd"&gt;As&lt;/span&gt; System.ComponentModel.ITypeDescriptorContext, &lt;span class="kwd"&gt;ByVal&lt;/span&gt; sourceType &lt;span class="kwd"&gt;As&lt;/span&gt; System.Type) &lt;span class="kwd"&gt;As Boolean
        If&lt;/span&gt; sourceType.Equals(&lt;span class="kwd"&gt;GetType&lt;/span&gt;(&lt;span class="kwd"&gt;String&lt;/span&gt;)) &lt;span class="kwd"&gt;Then
            Return True
        Else
            Return MyBase&lt;/span&gt;.CanConvertFrom(context, sourceType)
        &lt;span class="kwd"&gt;End If
    End Function

    Public Overrides Function&lt;/span&gt; CanConvertTo(&lt;span class="kwd"&gt;ByVal&lt;/span&gt; context &lt;span class="kwd"&gt;As&lt;/span&gt; System.ComponentModel.ITypeDescriptorContext, &lt;span class="kwd"&gt;ByVal&lt;/span&gt; destinationType &lt;span class="kwd"&gt;As&lt;/span&gt; System.Type) &lt;span class="kwd"&gt;As Boolean
        If&lt;/span&gt; destinationType.Equals(&lt;span class="kwd"&gt;GetType&lt;/span&gt;(&lt;span class="kwd"&gt;String&lt;/span&gt;)) &lt;span class="kwd"&gt;Then
            Return True
        Else
            Return MyBase&lt;/span&gt;.CanConvertTo(context, destinationType)
        &lt;span class="kwd"&gt;End If
    End Function

    Public Overrides Function&lt;/span&gt; ConvertFrom(&lt;span class="kwd"&gt;ByVal&lt;/span&gt; context &lt;span class="kwd"&gt;As&lt;/span&gt; System.ComponentModel.ITypeDescriptorContext, &lt;span class="kwd"&gt;ByVal&lt;/span&gt; culture &lt;span class="kwd"&gt;As&lt;/span&gt; System.Globalization.CultureInfo, &lt;span class="kwd"&gt;ByVal&lt;/span&gt; value &lt;span class="kwd"&gt;As Object&lt;/span&gt;) &lt;span class="kwd"&gt;As Object
        If TypeOf&lt;/span&gt; value &lt;span class="kwd"&gt;Is String Then
            Try
                Return CType&lt;/span&gt;([&lt;span class="kwd"&gt;Enum&lt;/span&gt;].Parse(&lt;span class="kwd"&gt;GetType&lt;/span&gt;(T), value, &lt;span class="kwd"&gt;True&lt;/span&gt;), T)
            &lt;span class="kwd"&gt;Catch
                Throw New&lt;/span&gt; InvalidCastException(value)
            &lt;span class="kwd"&gt;End Try
        Else
            Return MyBase&lt;/span&gt;.ConvertFrom(context, culture, value)
        &lt;span class="kwd"&gt;End If
    End Function

    Public Overrides Function&lt;/span&gt; ConvertTo(&lt;span class="kwd"&gt;ByVal&lt;/span&gt; context &lt;span class="kwd"&gt;As&lt;/span&gt; System.ComponentModel.ITypeDescriptorContext, &lt;span class="kwd"&gt;ByVal&lt;/span&gt; culture &lt;span class="kwd"&gt;As&lt;/span&gt; System.Globalization.CultureInfo, &lt;span class="kwd"&gt;ByVal&lt;/span&gt; value &lt;span class="kwd"&gt;As Object&lt;/span&gt;, &lt;span class="kwd"&gt;ByVal&lt;/span&gt; destinationType &lt;span class="kwd"&gt;As&lt;/span&gt; System.Type) &lt;span class="kwd"&gt;As Object
        If&lt;/span&gt; destinationType.Equals(&lt;span class="kwd"&gt;GetType&lt;/span&gt;(&lt;span class="kwd"&gt;String&lt;/span&gt;)) &lt;span class="kwd"&gt;Then
            Return&lt;/span&gt; value.ToString()
        &lt;span class="kwd"&gt;Else
            Return MyBase&lt;/span&gt;.ConvertTo(context, culture, value, destinationType)
        &lt;span class="kwd"&gt;End If
    End Function
End Class&lt;/span&gt;&lt;/pre&gt;&amp;nbsp;</description></item><item><title>Re: Enum as DepedencyProperty</title><link>http://forums.silverlight.net/forums/thread/211029.aspx</link><pubDate>Thu, 23 Apr 2009 16:52:31 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:211029</guid><dc:creator>DJanjicek</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/211029.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=17&amp;PostID=211029</wfw:commentRss><description>&lt;p&gt;I&amp;#39;ve found this article on the net, maybe it can be used to extend your implementation... &lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.kindblad.com/2008/08/18/how-to-convert-from-string-to-enum-using-c-and-generics/"&gt;http://www.kindblad.com/2008/08/18/how-to-convert-from-string-to-enum-using-c-and-generics/&lt;/a&gt;&lt;/p&gt;</description></item><item><title>Re: Enum as DepedencyProperty</title><link>http://forums.silverlight.net/forums/thread/211023.aspx</link><pubDate>Thu, 23 Apr 2009 16:41:21 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:211023</guid><dc:creator>wjchristenson2</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/211023.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=17&amp;PostID=211023</wfw:commentRss><description>&lt;p&gt;I&amp;#39;m sure you could create a generic enum converter.&amp;nbsp;M$ may have one out there that I&amp;#39;m not aware of.&amp;nbsp; I&amp;#39;ve not done a lot of searching on it.&amp;nbsp; Please post if you find one.&lt;/p&gt;</description></item><item><title>Re: Enum as DepedencyProperty</title><link>http://forums.silverlight.net/forums/thread/211010.aspx</link><pubDate>Thu, 23 Apr 2009 16:28:03 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:211010</guid><dc:creator>DJanjicek</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/211010.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=17&amp;PostID=211010</wfw:commentRss><description>&lt;p&gt;Thank you very much, i will try that tomorrow! i&amp;#39;m just curious, your solution dictates to have a particular converter for every enum i will work with. How much work would it be to implement a generic converter? If i look at all the out-of-the-box controls which actually use enums for their properties i doubt the MS guys have written a converter for every particular enum they&amp;#39;re using.&lt;/p&gt;</description></item><item><title>Re: Enum as DepedencyProperty</title><link>http://forums.silverlight.net/forums/thread/211007.aspx</link><pubDate>Thu, 23 Apr 2009 16:17:24 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:211007</guid><dc:creator>wjchristenson2</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/211007.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=17&amp;PostID=211007</wfw:commentRss><description>&lt;p&gt;You will need to create a TypeConverter for your property so that it will know how to convert from a string to your enumerated type.&amp;nbsp; I wrote a quick demo for you on my blog.&amp;nbsp; The link is below:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.mostlydevelopers.com/blog/post/2009/04/23/Set-an-Enum-Dependency-Property-with-XAML.aspx"&gt;http://www.mostlydevelopers.com/blog/post/2009/04/23/Set-an-Enum-Dependency-Property-with-XAML.aspx&lt;/a&gt;&lt;/p&gt;</description></item><item><title>Enum as DepedencyProperty</title><link>http://forums.silverlight.net/forums/thread/210978.aspx</link><pubDate>Thu, 23 Apr 2009 14:54:18 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:210978</guid><dc:creator>DJanjicek</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/210978.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=17&amp;PostID=210978</wfw:commentRss><description>&lt;p&gt;HI,&lt;/p&gt;
&lt;p&gt;can somebody tell me how to register a dependency property of type enum? My property is accessable in xaml, but not how you would expect from an enum (drop down, etc). And the runtime throws a weird exception which doesn&amp;#39;t make much sense...&lt;/p&gt;
&lt;p&gt;Thanks in advance...&lt;/p&gt;</description></item></channel></rss>