Xaml异常:“在'System.Windows.Markup.StaticResourceHolder'上提供值,引发异常。”

时间:2016-10-12 20:45:56

标签: c# wpf xaml custom-controls

尝试设计自定义控件,但我的项目无法运行。当我尝试构建时,它说“在System.Windows.Markup.StaticResourceHolder上提供价值”抛出异常。行号'6'和行位置'7'。“该行和位置是我在我的控件中定义“TargetType”的地方。

Generic.xaml(“破坏”的地方)

planeVertices[counter][0] = length - half;
planeVertices[counter][1] = 0.0f;
planeVertices[counter][2] = width - half;
counter++;

MySprite.cs

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

    <Style TargetType="{x:Type local:MySprite}" BasedOn = "{StaticResource {x:Type Image}}">
        <Setter Property="Source" Value="MySourceSprite.png"/>
    </Style>

</ResourceDictionary>

MainWindow.xaml

namespace CustomControl
{
public class MySprite : Image
{
    static MySprite()
    {
        DefaultStyleKeyProperty.OverrideMetadata(typeof(MySprite), new FrameworkPropertyMetadata(typeof(MySprite)));
    }
}
}

我没有提供什么“价值”?

0 个答案:

没有答案