访问本地程序集ValueConverters

时间:2012-06-28 16:22:29

标签: wpf local xml-namespaces

我在尝试在xaml usercontrol中添加ValueConverter时遇到了一些问题:

一开始我只是添加对本地命名空间的引用有问题,经过一些编译/清理/重新编译后,它似乎终于看到了自己。尽管如此,它仍然无法找到我的ValueConverter类,以检查程序集是否被引用为blah blah blah ..

这是我的XAML:

<UserControl x:Class="MySolution.GUI.StatusPanel"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:local="using:MySolution.GUI"
         mc:Ignorable="d" d:DesignHeight="400" d:DesignWidth="800">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/MySolution.Styles;component/Styles.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MySolution.Styles;component/Icons.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
        <Style ...>
            <Setter Property="Background" Value="{Binding Path=DataContext.Column2, Converter={local:RowValueConverter}}" />
        </Style>
    </UserControl.Resources>
...
</UserControl>

这是转换器:

namespace MySolution.GUI
{
    public class RowValueConverter : MarkupExtension, IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return Color.FromRgb(255, 255, 255);
        }

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

        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            return this;
        }
    }
}

现在,我不明白为什么它继续这样说 XML命名空间'clr-namespace:MySolution.GUI'中不存在标记'RowValueConverter'

我该如何解决这个问题?

由于

编辑:XAML文件的当前状态

...
xmlns:local="using:MySolution.GUI"
mc:Ignorable="d" d:DesignHeight="400" d:DesignWidth="800">
<UserControl.Resources>
    <local:RowValueConverter x:Key="rowValueConverter" />
    <ResourceDictionary>
    ...
    ...
    <Setter Property="Background" Value="{Binding Path=DataContext.Column2, Converter={StaticResource rowValueConverter}}" />
    ...

1 个答案:

答案 0 :(得分:0)

根据评论编辑更新的答案

添加以下

 < local:RowValueConverter x:key="rowValueConverter" />

之后

 < UserControl.Resources>

更改以下

Converter={local:RowValueConverter}

Converter={StaticResource rowValueConverter}

您尚未在任何地方定义资源,并尝试在现有代码中使用类名而不是资源


旧答案

更改

xmlns:local="MySolution.GUI"

xmlns:local="using:MySolution.GUI"

xmlns:local="clr-namespace:MySolution.GUI"
相关问题