控件库问题:无法创建“System.Type”来自文本“local:SolidGloss”

发布于 2024-09-28 15:43:24 字数 3233 浏览 3 评论 0原文

我正在开发一个自定义控件库,但我陷入了这个错误。谁能告诉我我错过了什么?

SolidGloss.cs:

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;

namespace UXSDK
{
public class SolidGloss : Control
{

    public SolidGloss()
        : base()
    {
        DefaultStyleKey = typeof(SolidGloss);
        //SolidGlossCorners_ConformToContainer();
    }

    Border SolidGloss_Container;
    Border SolidGloss_Upper;
    Border SolidGloss_Lower;

    public override void OnApplyTemplate()
    {
        SolidGloss_Container = this.GetTemplateChild("SolidGloss_Container") as Border;
        Debug.Assert(SolidGloss_Container != null, "SolidGloss_Container is null");

        SolidGloss_Upper = this.GetTemplateChild("SolidGloss_Container") as Border;
        Debug.Assert(SolidGloss_Container != null, "SolidGloss_Container is null");

        SolidGloss_Lower = this.GetTemplateChild("SolidGloss_Container") as Border;
        Debug.Assert(SolidGloss_Container != null, "SolidGloss_Container is null");

        base.OnApplyTemplate();
    }
    public CornerRadius SolidGlossCorners
    {
        get
        {
            return (CornerRadius)GetValue(SolidGlossCornersProperty);
        }
        set
        {
            SetValue(SolidGlossCornersProperty, value);
        }
    }
    public static readonly DependencyProperty SolidGlossCornersProperty = DependencyProperty.Register("SolidGlossCorners", typeof(CornerRadius), typeof(SolidGloss), new PropertyMetadata(new CornerRadius(20,20,20,20)));
}
}

generic.xaml:

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

<!-- shared styles -->

<!-- colors -->
<Color x:Key="SolidGloss_Color_Container">#19FFFFFF</Color>
<Color x:Key="SolidGloss_Color_Upper">#19FFFFFF</Color>
<Color x:Key="SolidGloss_Color_Lower">#33000000</Color>

<!-- measures -->
<CornerRadius x:Key="Solid_CornerRadius_Container_Full">6</CornerRadius>
<Thickness x:Key="SolidGloss_Thickness_Border">1</Thickness>

<!-- Solid Gloss Background Element -->
<Style TargetType="local:SolidGloss">
    <Setter Property="Template">
        <Setter.Value>
...Visual Design...
        </Setter.Value>
    </Setter>
</Style>

</ResourceDictionary>

MainPage.xaml(引用 UXSDK 程序集的单独项目)

<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:UX="clr-namespace:UXSDK;assembly=UXSDK"
x:Class="UXSDKTestBed.MainPage"
Width="640" Height="480" Foreground="#33000000">

<Grid x:Name="LayoutRoot" Background="#FF191919">
    <UX:SolidGloss Width="200" Height="32"/>
</Grid>
</UserControl>

I'm working on a library of custom controls and I'm stuck on this error. Can anyone tell me what I'm missing?

SolidGloss.cs:

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;

namespace UXSDK
{
public class SolidGloss : Control
{

    public SolidGloss()
        : base()
    {
        DefaultStyleKey = typeof(SolidGloss);
        //SolidGlossCorners_ConformToContainer();
    }

    Border SolidGloss_Container;
    Border SolidGloss_Upper;
    Border SolidGloss_Lower;

    public override void OnApplyTemplate()
    {
        SolidGloss_Container = this.GetTemplateChild("SolidGloss_Container") as Border;
        Debug.Assert(SolidGloss_Container != null, "SolidGloss_Container is null");

        SolidGloss_Upper = this.GetTemplateChild("SolidGloss_Container") as Border;
        Debug.Assert(SolidGloss_Container != null, "SolidGloss_Container is null");

        SolidGloss_Lower = this.GetTemplateChild("SolidGloss_Container") as Border;
        Debug.Assert(SolidGloss_Container != null, "SolidGloss_Container is null");

        base.OnApplyTemplate();
    }
    public CornerRadius SolidGlossCorners
    {
        get
        {
            return (CornerRadius)GetValue(SolidGlossCornersProperty);
        }
        set
        {
            SetValue(SolidGlossCornersProperty, value);
        }
    }
    public static readonly DependencyProperty SolidGlossCornersProperty = DependencyProperty.Register("SolidGlossCorners", typeof(CornerRadius), typeof(SolidGloss), new PropertyMetadata(new CornerRadius(20,20,20,20)));
}
}

generic.xaml:

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

<!-- shared styles -->

<!-- colors -->
<Color x:Key="SolidGloss_Color_Container">#19FFFFFF</Color>
<Color x:Key="SolidGloss_Color_Upper">#19FFFFFF</Color>
<Color x:Key="SolidGloss_Color_Lower">#33000000</Color>

<!-- measures -->
<CornerRadius x:Key="Solid_CornerRadius_Container_Full">6</CornerRadius>
<Thickness x:Key="SolidGloss_Thickness_Border">1</Thickness>

<!-- Solid Gloss Background Element -->
<Style TargetType="local:SolidGloss">
    <Setter Property="Template">
        <Setter.Value>
...Visual Design...
        </Setter.Value>
    </Setter>
</Style>

</ResourceDictionary>

MainPage.xaml (seperate project referencing the UXSDK assembly)

<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:UX="clr-namespace:UXSDK;assembly=UXSDK"
x:Class="UXSDKTestBed.MainPage"
Width="640" Height="480" Foreground="#33000000">

<Grid x:Name="LayoutRoot" Background="#FF191919">
    <UX:SolidGloss Width="200" Height="32"/>
</Grid>
</UserControl>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最后的乘客 2024-10-05 15:43:24

你的程序集名称肯定是UXSDK吗?您是否尝试过从 XML 命名空间映射中删除空格?

xmlns:local="clr-namespace:UXSDK;assembly=UXSDK"

Is your assembly name definitely UXSDK? Have you tried removing the space from your XML namespace mapping?

xmlns:local="clr-namespace:UXSDK;assembly=UXSDK"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文