开发者

ContentControl does not render at another Assembly

开发者 https://www.devze.com 2023-03-26 17:54 出处:网络
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).

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号