VS2013:查找资源字典时发生错误/类型不是名称空间的一部分

哈瑟

我正在开发一个自定义控件,这是到目前为止的内容:

主题/Generic.xaml

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Themes/ColorPicker.xaml" />
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

控件/ColorPicker.cs

namespace TrigDebugUtil.Controls
{
    public class ColorPicker : Control
    {
        #region Private Fields

        #endregion //Private Fields

        #region Properties
        public BitmapImage ColorWheelImage
        {
            get;
            private set;
        }
        #endregion //Properties

        static ColorPicker()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(ColorPicker), new FrameworkPropertyMetadata(typeof(ColorPicker)));
        }

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            WriteableBitmap ColorDrawboard;
        }
    }
}

主题/ColorPicker.xaml

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:TrigDebugUtil.Controls">


    <Style TargetType="{x:Type local:ColorPicker}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:ColorPicker}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                        <!-- <Image Source="{TemplateBinding ColorWheelImage}" /> -->
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>

App.xaml

<Application x:Class="TrigDebugUtil.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:cont="clr-namespace:TrigDebugUtil.Controls"
             StartupUri="MainWindow.xaml">

    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Themes/Generic.xaml" />
            </ResourceDictionary.MergedDictionaries>

            <Style TargetType="{x:Type cont:ColorPicker}" BasedOn="{StaticResource ColorPicker}" />
        </ResourceDictionary>
    </Application.Resources>
</Application>

我现在遇到了很多错误,所有人都这样说:

类型或名称空间“ ColorPicker”在名称空间“ TrigDebugUtil.Controls”中不存在

搜索资源字典“ Themes / Generic.xaml”时发生错误

如果我将相关的行替换为

pack://application:,,,/Trig.DebugUtil;component/Themes/ColorPicker.xaml

该错误被该项目未引用的警告“ Trig.DebugUtil”程序集代替(免费翻译)

不管错误如何,项目似乎都可以编译(控制台输出中没有错误消息,仅在错误列表中)

罗希特·瓦茨(Rohit Vats)

您应该BasedOn="{StaticResource {x:Type cont:ColorPicker}}"确定使用您使用的语法仅适用于WPF提供的默认控件,但对于自定义控件,您必须提供确切的类型。

同样对于TemplateBinding,属性应该是依赖项属性,而不是CLR属性。您已将ColorWheelImage声明为常规CLR属性,但应将其声明为Dependency属性

句法:

public BitmapImage ColorWheelImage
{
    get { return (BitmapImage)GetValue(ColorWheelImageProperty); }
    set { SetValue(ColorWheelImageProperty, value); }
}

public static readonly DependencyProperty ColorWheelImageProperty =
    DependencyProperty.Register("ColorWheelImage", typeof(BitmapImage), 
                                 typeof(ColorPicker));

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在资源字典中使文本的一部分加粗

当项目包含多个EDMX文件时,抛出“实体类型不是当前上下文模型的一部分”错误

Python-根据名称的一部分查找文件夹的名称

`nullptr_t`应该成为全局名称空间的一部分吗?

fabsf是C ++ 11中std名称空间的一部分吗?

如何使用python在硒中按ID名称的一部分查找元素

文档querySelectorAll查找元素的属性名称的一部分?

如何在目录中查找知道名称一部分的文件

查找工作表名称的一部分

MySQL查询以查找字符串的一部分是否不是数字

JAXB元帅错误发生之前创建文件的一部分

从json文件的一部分创建字典

提取字典文件的一部分

将字典的一部分与副本合并

在python中获得字典的一部分

从字典中获取一部分

关联容器,比较函数不是元素类型的一部分吗?

实体类型IdentityUser不是当前上下文模型的一部分

实体类型ApplicationUser不是当前上下文模型的一部分

实体类型ApplicationUser不是当前上下文模型的一部分

联合而不是aligned_storage_t作为容器节点类型的一部分

实体类型<T>不是当前上下文模型的一部分

实体类型<type>不是当前上下文模型的一部分

为什么联接是独立的,而不是Monad类型类的最小实现的一部分?

实体类型[class]不是当前上下文模型的一部分

使用ID的一部分查找元素

删除名称列表的一部分

排序名称的一部分

PowerShell:删除显示名称的一部分