Windows store apps 使用值转换器绑定到universal app中的可见性

Windows store apps 使用值转换器绑定到universal app中的可见性,windows-store-apps,win-universal-app,resourcedictionary,ivalueconverter,Windows Store Apps,Win Universal App,Resourcedictionary,Ivalueconverter,接下来,我们需要创建一个转换器,在布尔值和可见性之间进行转换。这是: namespace DictionaryApp.Model { public class VisiableConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, string language) { thr

接下来,我们需要创建一个转换器,在布尔值和可见性之间进行转换。这是:

   namespace DictionaryApp.Model
{
    public class VisiableConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            throw new NotImplementedException();
        }

        public object Convert(
        object value,
        Type targetType,
        object parameter,
        CultureInfo culture)
        {
            bool visibility = (bool)value;
            return visibility ? Visibility.Visible : Visibility.Collapsed;
        }

        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            throw new NotImplementedException();
        }

        public object ConvertBack(
            object value,
            Type targetType,
            object parameter,
            CultureInfo culture)
        {
            Visibility visibility = (Visibility)value;
            return (visibility == Visibility.Visible);
        }
    }
}
接下来,在UserControl的资源中添加转换器。在我的简单项目中,我必须创建此部分-但希望您已经在实际应用中使用了此部分

您可能还需要在page.xaml中为项目的命名空间添加一个xmlns属性

x:Class="DictionaryApp.PageDictionary"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:DictionaryApp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ms="using:DictionaryApp.Model"
mc:Ignorable="d">
<UserControl.Resources>
    <ms:VisiableConverter x:Key="VisiableConverter"></ms:VisiableConverter>
</UserControl.Resources>
x:Class=“DictionaryApp.PageDictionary”
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local=“使用:DictionaryApp”
xmlns:d=”http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ms=“使用:DictionaryApp.Model”
mc:Ignorable=“d”>

名称空间中不存在名称“XYZ”“axy

试试这个:
,VisibilityConverter类是在没有指定名称空间的情况下定义的,因此它应该位于全局名称空间内,即
字典应用程序
,这就是为什么我使用
本地:
前缀的原因。你的意思是我的代码可以工作,但是你尝试添加
字典应用程序.Model
名称空间,并且出现新错误?此处名称“XYZ”不存在于命名空间“axy”中在您的情况下“XYZ”和“axy”是什么?