1

I getting XamlParseException when try to use converter. I suspect that I made a mistake in converter but can't catch it.

Full error text:

A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in System.Windows.ni.dll

Additional information: Cannot create instance of type 'app.Converters.DimensionToText' [Line: 21 Position: 42]

namespace app.Converters
{
    class DimensionToText : IValueConverter
    {
        public object Convert(object value, Type targetType,
            object parameter, CultureInfo culture)
        {
            Dimensions dim = (Dimensions) value;
            //bool param = (bool) parameter;
            return dim.width.ToString().Trim() + "\"x " + dim.length.ToString().Trim() + "\"x " + dim.height.ToString().Trim() + "\"";
        }

        public object ConvertBack(object value, Type targetType,
                object parameter, CultureInfo culture)
        {
            return value;
        }
    }
}

XAML parts:

xmlns:converter="clr-namespace:app.Converters"
...
<phone:PhoneApplicationPage.Resources>
    <converter:DimensionToText x:Key="DimensionToText"/>
</phone:PhoneApplicationPage.Resources>
...
<TextBlock Style="{StaticResource PhoneTextNormalStyle}"> 
    <Run Text="Dimensions:"/>
    <Run Text="{Binding information.dimensions, Converter={StaticResource DimensionToText}}"/>
</TextBlock>

Strangely in design time converter works just fine. Any suggestions appreciated

2
  • 2
    Does making the converter a public class change the behavior? Commented Apr 23, 2014 at 19:34
  • @Vkt0rS. Your edit did not improve the formatting here. It just made the error harder to read. Commented Apr 24, 2014 at 6:28

1 Answer 1

2

Make your converter public

namespace app.Converters
{
    public class DimensionToText : IValueConverter
    {
        public object Convert(object value, Type targetType,
            object parameter, CultureInfo culture)
        {
            Dimensions dim = (Dimensions) value;
            //bool param = (bool) parameter;
            return dim.width.ToString().Trim() + "\"x " + dim.length.ToString().Trim() + "\"x " + dim.height.ToString().Trim() + "\"";
        }

        public object ConvertBack(object value, Type targetType,
                object parameter, CultureInfo culture)
        {
            return value;
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.