在 wpf 中使用 UserControl 作为基础 class 显示为空

Using UserControl as base class in wpf is showing empty

您好,我在我的演示项目中使用了 Prism,但我遇到了用户控件继承方面的问题。如果我将我的用户控件库 class 用于我的用户控件,如下所示,用户控件的内容显示为空。然后当我使用

<igf:UserControlBase x:Class="DemoProject.Views.DemoView"
         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:igf="http://igf.schema"
         mc:Ignorable="d" d:DesignWidth="300" d:DesignHeight="200">
             <StackPanel>
                 <TextBox Text="Hello Prism"/>
                 <TextBlock Text="Hello Prism"></TextBlock>
             </StackPanel>
</igf:ViewControlBase>

这是我的用户控件,它在另一个项目中。现在对 ctors 进行了评论,但仍然无法正常工作。唯一的方式在改变

using System.Windows;
using System.Windows.Controls;

namespace DemoProject.Base.Controls
{
    public class UserControlBase : UserControl
    {
        static UserControlBase()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(UserControlBase), new FrameworkPropertyMetadata(typeof(UserControlBase)));
        }

        public UserControlBase()
        {
            DefaultStyleKey = typeof(UserControlBase);
        }
    }
}

我通过将以下代码添加到用户控件项目的 Assembly.cs 文件中找到了解决方案

[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]