简体   繁体   中英

WPF Custom window invisible

I have this structure:

在此处输入图片说明

LightWindow.cs

namespace ScreenToGif.Controls.LightWindow
{
    public class LightWindow : Window
    {
        static LightWindow()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(LightWindow), new FrameworkPropertyMetadata(typeof(LightWindow)));
        }
     //...
    }
 }

Recorder.xaml

<lightWindow:LightWindow x:Class="ScreenToGif.Windows.Recorder"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:lightWindow="clr-namespace:ScreenToGif.Controls.LightWindow"
</lightWindow:LightWindow>

Generic.xaml

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:lightWindow="clr-namespace:ScreenToGif.Controls.LightWindow">

<!-- Window style -->
<Style TargetType="{x:Type lightWindow:LightWindow}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type lightWindow:LightWindow}">
<!-- closing tags omitted -->

Problem:

The Recorder window opens up invisible. In my test project (a dll with the custom window inside being used in another project), the window shows up correctly.

The only thing that shows up is the internal grid of the Recorder window if I remove the OverrideMetadata call (not what I want).

How to make to work:

在此处输入图片说明

Move the Themes resource to the root folder of the project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM