In my application I have
<Rectangle.Margin>
<MultiBinding Converter="{StaticResource XYPosToThicknessConverter}">
<Binding Path="XPos"/>
<Binding Path="YPos"/>
</MultiBinding>
</Rectangle.Margin>
The Data Context is set during runtime. The application works, but the design window in VS does not show a preview but System.InvalidCastException. That’s why I added a default object in the XYPosToThicknessConverter which is ugly.
class XYPosToThicknessConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
// stupid check to give the design window its default object.
if (!(values[0] is IConvertible))
return new System.Windows.Thickness(3, 3, 0, 0);
// useful code and exception throwing starts here
// ...
}
}
My Questions:
- What does VS/the process that builds the design window pass to XYPosToThicknessConverter and what is way to find it out by myself.
- How do I change my XAML code, so that the design window gets its default object and is this the best way to handle this problem?
I’m using VS2010RC with Net4.0