views:

318

answers:

2

Hi,

I have a dependency property in a class which I need to be converted to a string.

I have added the TypeConverty attribute on the property. The type I am converting is the .net Style class.

    [TypeConverter(typeof(BulletStyleTypeConverter))]
    public Style BulletStyle
    {
        get { return (Style)GetValue(BulletStyleProperty); }
        set { this.SetValue(BulletStyleProperty, value); }
    }

When I put the string "Rectangle" in for BulletStyle in xaml it hits the ConvertFrom method in my converter.

However, when I use XamlWriter.Save() to serialise this, the property does not appear as an attribute in the string which is produced.

I have implemented ConvertTo and put a breakpoint on, which is never hit.

I have implemented CanConvertTo and put a breakpoint on, which IS hit and returns true. So i'm stumped as to why ConvertTo never fires.

A: 

I got the same question.

Cooper.Wu
A: 

http://bryantlikes.com/SilverlightIValueConverterVsTypeConverter.aspx

IValueConventer used in a binding expression. and TypeConverter just used set the value directly, e.g. set Height="222" in xmal. In this case, the TypeConverter will convert string "222" to a GridLength value.

Cooper.Wu