我在主程序集(WPF应用程序)中创建了一些自定义控件并对其进行了测试 - 一切正常。然后我将此控件替换为单独的程序集(EB.Controls)。
在启动程序集(WPF应用程序)中,我添加了/Themes/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="/EB.Controls;component/HeadButton.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
但是控制没有渲染。 这是我的对照XAML:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Controls="clr-namespace:EB.Controls" >
<ControlTemplate TargetType="Controls:HeadButton" x:Key="HeadButtonTemplate">
<Border Background="{TemplateBinding Background}"
CornerRadius="0.2"
BorderBrush="White" BorderThickness="1">
<Grid>
<ContentPresenter/>
</Grid>
</Border>
</ControlTemplate >
<Style TargetType="Controls:HeadButton">
<Setter Property="Template" Value="{StaticResource HeadButtonTemplate}"/>
</Style>
</ResourceDictionary>
和.cs:
namespace EB.Controls
{
[TemplateVisualState(Name = VisualStates.MouseOver, GroupName = VisualStates.CommonStates)]
[TemplateVisualState(Name = VisualStates.Normal, GroupName = VisualStates.CommonStates)]
public class HeadButton : Button
{
public HeadButton()
{
DefaultStyleKey = typeof (HeadButton);
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
}
}
我犯错误的地方?
答案 0 :(得分:0)
因为你把它移到另一个组件,你需要修改你的Uri类似的东西; 包://应用:,,, / ReferencedAssembly;组件/ ResourceFile.xaml
有关详细信息,请参阅MSDN