Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.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
Xaml 为什么在尝试将转换器添加到ResourceDictionary时出现此错误?_Xaml_Windows Phone 7_Windows Phone 8_Windows Phone_Converter - Fatal编程技术网

Xaml 为什么在尝试将转换器添加到ResourceDictionary时出现此错误?

Xaml 为什么在尝试将转换器添加到ResourceDictionary时出现此错误?,xaml,windows-phone-7,windows-phone-8,windows-phone,converter,Xaml,Windows Phone 7,Windows Phone 8,Windows Phone,Converter,我尝试将转换器添加到ResourceDictionary,因为我需要使用它,但当我只添加去极化时,在运行应用程序时会出现错误 以下是如何添加转换器声明: <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:System="clr-namespac

我尝试将转换器添加到ResourceDictionary,因为我需要使用它,但当我只添加去极化时,在运行应用程序时会出现错误

以下是如何添加转换器声明:

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"   
xmlns:System="clr-namespace:System;assembly=mscorlib"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 
xmlns:Command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WP71"
xmlns:converters="clr-namespace:Sample.Utility.Converters">

<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter"/>
我尝试将转换器添加到,但结果相同

有人能帮我解决我的问题吗


这是我的转换器的代码

public class BoolToVisibilityConverter : IValueConverter
{
    #region IValueConverter Members

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        bool visible = (bool)value;

        return (visible ? Visibility.Visible : Visibility.Collapsed);

    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        Visibility vis = (Visibility)value;
        switch (vis)
        {
            case Visibility.Collapsed:
                return false;
            case Visibility.Visible:
                return true;
        }
        return null;
    }

    #endregion
}

要使资源字典在应用程序中全局可用,您需要在
app.xaml中这样合并它:

<Application x:Class="Sample.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Application.Resources>
    <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/uri/to/resource_dictionary.xaml"/>
      </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
  </Application.Resources>
</Application>


能否显示转换器的代码?该转换器类实际上位于
Sample.Utility.Converters
命名空间中?能否尝试将xmlns:Converters=“clr namespace:Sample.Utility.Converters”移动到PhoneApplicationPage或应用程序定义(顶部)或者直接到转换器:BoolToVis xmlns:…?当我将其添加到任何页面或用户控件时,它都会工作,但在ResourceDictionary或App.xaml中都不工作。您知道如何修复它吗?
<Application x:Class="Sample.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Application.Resources>
    <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/uri/to/resource_dictionary.xaml"/>
      </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
  </Application.Resources>
</Application>