icsharpcode / WpfDesigner

The WPF Designer from SharpDevelop
MIT License
949 stars 251 forks source link

use type converter for converting instance values when available instead of direct casting #105

Closed LukeOrdelmans closed 1 year ago

LukeOrdelmans commented 1 year ago

Added GetValueOnInstance<T>() on DesignItemProperty.cs implemented in XamlProperty.cs that uses the TypeConverter when available before doing a direct cast.

This allows users to replace properties on FrameworkElement deratives, e.g. public new ScriptableThickness Margin { get; set; ] as long as they provide a matching TypeConverter that can convert to the original type, Thickness in this case.

jogibear9988 commented 1 year ago

Du you think the Name GetValueOnInstance is okay? Maybe something like GetConvertedValueOnInstance would be better? So it indicates that a conversion is done? Do we need a coresponding set method using a converter?

LukeOrdelmans commented 1 year ago

Agreed, GetConvertedValueOnInstance is more clear, I updated the PR. I think a corresponding set method is not required as the ValueOnInstance property is of type object, so it always will accept any assigned value/type directly.

jogibear9988 commented 1 year ago

thx