运行时错误:资源字典中的“未找到类型”

时间:2014-05-30 13:41:52

标签: c# xaml windows-runtime winrt-xaml

我有Generic.xaml字典文件,其中包含转换器定义。当我运行应用程序时,它会引发异常:

A first chance exception of type 'Windows.UI.Xaml.Markup.XamlParseException' occurred in METRO.SimpleGraph.exe
WinRT information: The type 'VisibilityToBoolConverter' was not found. [Line: 14 Position: 58]
Additional information: The text associated with this error code could not be found.

转换器:

namespace GraphX.Converters
{
  public sealed class VisibilityToBoolConverter : IValueConverter
  {
    public bool Inverted { get; set; }
    public bool Not { get; set; }

    public object Convert(object value, Type targetType, object parameter, string language)
    {
      return this.Inverted ? this.BoolToVisibility( value ) : this.VisibilityToBool( value );
    }

    public object ConvertBack(object value, Type targetType, object parameter, string language)
    {
      return this.Inverted ? this.VisibilityToBool( value ) : this.BoolToVisibility( value );
    }

    private object VisibilityToBool( object value )
    {
      if( !( value is Visibility ) )
        throw new InvalidOperationException( "SuppliedValueWasNotVisibility" );

      return ( ( ( Visibility )value ) == Visibility.Visible ) ^ Not;
    }

    private object BoolToVisibility( object value )
    {
      if( !( value is bool ) )
        throw new InvalidOperationException( "SuppliedValueWasNotBool" );

      return ( ( bool )value ^ Not ) ? Visibility.Visible : Visibility.Collapsed;
    }
  }
}

字典:

xmlns:conv="using:GraphX.Converters"

<conv:VisibilityToBoolConverter x:Key="VisibleIfNotTrueConverter"

我甚至不必在任何地方使用它。代码编译得很好,所有名称空间和名称似乎都是正确的。 WinRT有任何限制吗?因为此代码在WPF中正常工作。

2 个答案:

答案 0 :(得分:1)

这个问题的解决方案并不明显。您必须为错误的类设置 [Bindable] 属性,以强制正确完成元数据生成。老实说,我不明白为什么有些类会抛出这个错误。您还可以在该问题中找到一些信息:Loading Loose Xaml with custom controls on WinRT fails unless dummy DataTemplate exists

答案 1 :(得分:0)

您是否尝试使用以下语法插入命名空间:     的xmlns:CONV =&#34; CLR-名称空间:GraphX.Converters&#34; ?