dotnet / wpf

WPF is a .NET Core UI framework for building Windows desktop applications.
MIT License
7.08k stars 1.17k forks source link

Window CustomControl is not stylized at design time. #4524

Closed jamesnet214 closed 3 years ago

jamesnet214 commented 3 years ago

Window CustomControl is not stylized at design time.

CustomWindow and CustomUserControl

public class CustomWindow : Window
{
    static CustomWindow
    {
        DefaultStyleKeyProperty.OverrideMetadata(
            typeof(CustomWindow), 
            new FrameworkPropertyMetadata(typeof(CustomWindow)));
    }
}

public class CustomUserControl : UserControl
{
    static CustomUserControl 
    {
        DefaultStyleKeyProperty.OverrideMetadata(
            typeof(CustomUserControl), 
            new FrameworkPropertyMetadata(typeof(CustomUserControl)));
    }
}

Generic.xaml

<Style TargetType="{x:Type local:CustomWindow}">
    <Setter Property="Background" Value="Blue"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:CustomWindow}">
                <Border Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}" Padding="10">
                    <ContentPresenter/>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

<Style TargetType="{x:Type local:CustomUserControl}">
    <Setter Property="Background" Value="Green"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:CustomUserControl}">
                <Border Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}">
                    <ContentPresenter/>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

MyWindow and MyUserControl

public partial class MyWindow : CustomWindow
{
    // DesignTime not stylized.
}

public partial class MyUserControl : CustomUserControl
{
    // DesignTime stylized.
}
<!-- MyWindow.xaml -->
<custom:MyWindow ...>
    <Grid>
    </Grid>
</custom:MyWindow>

<!-- MyUserControl.xaml -->
<custom:MyUserControl ...>
    <Grid>
    </Grid>
</custom:MyUserControl>

MyWindow(CustomWindow) DesignTime not stylized.

image

MyUserControl(CustomUserControl) DesignTime stylized.

image

The style is well applied when it is Runtime.

Symbai commented 3 years ago

If this is a VS designer only issue (i.e. happens only in the VS designer), you should report this in VS ( Help -> Send feedback -> Report a problem). The team that works on the XAML designer in VS is a different team than WPF team. And the good news is that the XAML designer team is also a lot more active.

jamesnet214 commented 3 years ago

@Symbai Thank you 👍 I registered the issue in Visual Studio report as you advised.

Have a good day.

ryalanms commented 3 years ago

@devncore-james: WPF doesn't own the designer. This is a VS issue. Can you close this one? Thanks.

jamesnet214 commented 3 years ago

Thank you for your answer. :)