我试图为我的WPF应用程序创建自定义控件,并且无法理解它为什么不能正常工作。来自WPF应用程序中的自定义控件的异常
我有两个项目 - 一个是我的自定义控件库,其中一个自定义控件源自Image
,只有很少的方法,第二个项目我想使用我的控件。我不想做任何样式或绑定,所以我使用默认值。
所以,我的自定义控件主题(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:RTPlayer">
<Style
TargetType="{x:Type local:RTPlayer}" BasedOn="{StaticResource {x:Type Image}}">
</Style>
和代码部分:
namespace RTPlayer
{
public class RTPlayer : Image
{
static RTPlayer()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(RTPlayer), new FrameworkPropertyMetadata(typeof(RTPlayer)));
}
public void Start()
{
// ....
}
}
}
在我的主要项目中,我已经添加引用到我的图书馆。 DLL文件,我试图使用控制:
<Window x:Class="rtspWPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:rtspWPF"
xmlns:CustomControls="clr-namespace:RTPlayer;assembly=RTPlayer"
xmlns:CustomControls="clr-namespace:RTPlayer;assembly=RTPlayer"
Title="MainWindow" Height="auto" Width="auto">
<CustomControls:RTPlayer x:Name="image" Margin="10,10,10,10" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="auto" Height="auto"/>
问题是 - 1)xaml CustomControl:RTPlayer
字符串警告我:“无法找到名为”System.Windows.Controls.Image“的资源。资源名称是区分大小写的“; 2)如果我尝试启动应用其抛出Markup.XamlParseException
是Markup.StaticResourceHolder
抛出异常..
什么是错我的代码
你可以发布'XamlParseException.InnerException'的堆栈跟踪吗? – haindl
图像控件没有可以在样式中继承的基础样式。 – 2016-10-10 18:27:23