I created some custom control in main assembly (WPF Application) and tested it - all was be ok. Then I replaced this control to the separate assembly (EB.Controls).
At the start up assembly (WPF Application) I added /Themes/generic.xaml file to import my custom control:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsof开发者_高级运维t.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/EB.Controls;component/HeadButton.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
But control does not render. Here is the my control 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>
And .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();
}
}
Where I've done mistake?
Since you moved it to another assembly, you need to modify your Uri something similar like; pack://application:,,,/ReferencedAssembly;component/ResourceFile.xaml
See MSDN for more details
精彩评论