【问题标题】:ContentControl does not render at another AssemblyContentControl 不在另一个程序集中呈现
【发布时间】:2011-08-09 10:21:18
【问题描述】:

我在主程序集(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();
        }
    }

我哪里做错了?

【问题讨论】:

    标签: wpf controltemplate resourcedictionary


    【解决方案1】:

    由于您将其移至另一个程序集,您需要修改您的 Uri 类似的东西; pack://application:,,,/ReferencedAssembly;component/ResourceFile.xaml

    详情请见MSDN

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-01
      • 1970-01-01
      • 2011-07-16
      • 1970-01-01
      相关资源
      最近更新 更多