Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用转换器时发生XamlParseException_C#_Windows Phone 8_Ivalueconverter - Fatal编程技术网

C# 使用转换器时发生XamlParseException

C# 使用转换器时发生XamlParseException,c#,windows-phone-8,ivalueconverter,C#,Windows Phone 8,Ivalueconverter,我在尝试使用转换器时遇到XamlParseException。我怀疑我在转换器上犯了一个错误,但没能抓住它 错误全文: 类型的第一次机会例外 中出现“System.Windows.Markup.XamlParseException” System.Windows.ni.dll 其他信息:无法创建类型为的实例 “应用程序转换器尺寸文本”[行:21位置:42] XAML部件: xmlns:converter="clr-namespace:app.Converters" ... <phone:P

我在尝试使用转换器时遇到XamlParseException。我怀疑我在转换器上犯了一个错误,但没能抓住它

错误全文:

类型的第一次机会例外 中出现“System.Windows.Markup.XamlParseException” System.Windows.ni.dll

其他信息:无法创建类型为的实例 “应用程序转换器尺寸文本”[行:21位置:42]

XAML部件:

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>
xmlns:converter=“clr命名空间:app.Converters”
...
...

奇怪的是,在设计中,时间转换器工作得很好。欢迎任何建议

公开您的转换器

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;
        }
    }
}

将转换器设置为公共类是否会改变行为?@Vkt0rS。您的编辑没有改进此处的格式。这只会使错误更难阅读。
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;
        }
    }
}