Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[doc bug]: Incomplete template for Window #1997

Closed
tonyhallett opened this issue Feb 5, 2025 · 6 comments · Fixed by #2003
Closed

[doc bug]: Incomplete template for Window #1997

tonyhallett opened this issue Feb 5, 2025 · 6 comments · Fixed by #2003
Assignees
Labels
doc-bug Problem with the content; needs to be fixed [org][type][category] dotnet-framework/svc in-pr okr-quality Pri1 High priority, do before Pri2 and Pri3 📌 seQUESTered Label to indicate an item has been imported. wpf/subsvc

Comments

@tonyhallett
Copy link

tonyhallett commented Feb 5, 2025

Type of issue

Other (describe below)

Description

Edit by adegeo to convert the issue to the feedback link on the page

The Trigger below refers to a non existent static resource.

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <Style x:Key="WindowStyle1" TargetType="{x:Type Window}">
        <Setter Property="Foreground"
                Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>
        <Setter Property="Background"
                Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Window}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                        <AdornerDecorator>
                            <ContentPresenter/>
                        </AdornerDecorator>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="Window.ResizeMode"
                     Value="CanResizeWithGrip">
                <Setter Property="Template"
                        Value="{StaticResource WindowTemplateKey}"/>
            </Trigger>
        </Style.Triggers>
    </Style>

</ResourceDictionary>

Taken from aero

  <ControlTemplate x:Key="Ǡ" TargetType="{x:Type Window}">
    <Border Background="{TemplateBinding Control.Background}"
            BorderBrush="{TemplateBinding Control.BorderBrush}"
            BorderThickness="{TemplateBinding Control.BorderThickness}">
      <Grid>
        <AdornerDecorator>
          <ContentPresenter/>
        </AdornerDecorator>
        <ResizeGrip x:Name="WindowResizeGrip" HorizontalAlignment="Right" VerticalAlignment="Bottom"
                    Visibility="Collapsed" IsTabStop="false"/>
      </Grid>
    </Border>
    <ControlTemplate.Triggers>
      <MultiTrigger>
        <MultiTrigger.Conditions>
          <Condition Property="Window.ResizeMode" Value="CanResizeWithGrip"/>
          <Condition Property="Window.WindowState" Value="Normal"/>
        </MultiTrigger.Conditions>
        <Setter TargetName="WindowResizeGrip" Property="UIElement.Visibility" Value="Visible"/>
      </MultiTrigger>
    </ControlTemplate.Triggers>
  </ControlTemplate>
  <Style TargetType="{x:Type Window}">
    <Setter Property="Control.Foreground"
            Value="{DynamicResource {x:Static JetSystemColors.WindowTextBrushKey}}"/>
    <Setter Property="Control.Background" Value="{DynamicResource {x:Static JetSystemColors.WindowBrushKey}}"/>
    <Setter Property="Control.Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type Window}">
          <Border Background="{TemplateBinding Control.Background}"
                  BorderBrush="{TemplateBinding Control.BorderBrush}"
                  BorderThickness="{TemplateBinding Control.BorderThickness}">
            <AdornerDecorator>
              <ContentPresenter/>
            </AdornerDecorator>
          </Border>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
    <Style.Triggers>
      <Trigger Property="Window.ResizeMode" Value="CanResizeWithGrip">
        <Setter Property="Control.Template" Value="{StaticResource Ǡ}"/>
      </Trigger>
    </Style.Triggers>
  </Style>

Page URL

https://learn.microsoft.com/en-us/dotnet/desktop/wpf/controls/window-styles-and-templates?view=netframeworkdesktop-4.8

Content source URL

https://github.com/dotnet/docs-desktop/blob/main/dotnet-desktop-guide/framework/wpf/controls/window-styles-and-templates.md

Document Version Independent Id

c1f96787-03b0-7740-51fb-9722a9609198

Article author

@adegeo

Metadata

  • ID: 844e0881-ff9c-8374-6080-3c24ae15cb48
  • Service: dotnet-framework
  • Sub-service: wpf

Related Issues


Associated WorkItem - 371157

@tonyhallett tonyhallett added doc-bug Problem with the content; needs to be fixed [org][type][category] Pri1 High priority, do before Pri2 and Pri3 labels Feb 5, 2025
@adegeo adegeo removed the ⌚ Not Triaged Not triaged label Feb 7, 2025
@adegeo
Copy link
Contributor

adegeo commented Feb 7, 2025

Thank you for reporting this. I'm not sure where the original code is that was used to create these modified templates. As I get notified to these out-of-date templates, I just go in and edit them to put the default template in.

@adegeo adegeo added the 🗺️ reQUEST Trigger label to import an issue into Quest label Feb 7, 2025
@dotnetrepoman dotnetrepoman bot added the 🗺️ mapQUEST Only used as a way to mark an issue as updated. RepoMan should instantly remove it. label Feb 7, 2025
@dotnet-policy-service dotnet-policy-service bot removed the 🗺️ mapQUEST Only used as a way to mark an issue as updated. RepoMan should instantly remove it. label Feb 7, 2025
@adegeo
Copy link
Contributor

adegeo commented Feb 7, 2025

Yikes. It looks like this template was already "fixed."

What OS, Visual Studio version, and .NET Framework version are you using?

@adegeo adegeo added the needs-more-info Needs more info from OP. Auto-closed after 2 weeks if no response. [org][resolution] label Feb 7, 2025
@tonyhallett
Copy link
Author

Yikes. It looks like this template was already "fixed."

What do you mean by fixed. The documentation page nor the snippet page has changed.
Both reference a static resource WindowTemplateKey ( in the trigger ) that has not been shown.

The one I pasted in, which I believe I got from Visual Studio directory, also has a trigger that will set the control template "Ǡ"

@dotnet-policy-service dotnet-policy-service bot removed the needs-more-info Needs more info from OP. Auto-closed after 2 weeks if no response. [org][resolution] label Feb 8, 2025
@sequestor sequestor bot added 📌 seQUESTered Label to indicate an item has been imported. and removed 🗺️ reQUEST Trigger label to import an issue into Quest labels Feb 8, 2025
@adegeo
Copy link
Contributor

adegeo commented Feb 10, 2025

When I said fixed, I meant solving the problem of the incomplete templates, which for this specific template was 2 years ago. All of the templates shown seem to have been created over 10 years ago and they provide all sorts of customizations to them. When issues come up with them, I just revert them to what Visual Studio generates when you right-click on a control and ask it to generate a copy.

Looking into this one again, I don't see where this trigger came from. When I go in and generate the template now, I get a very simple style without the triggers:

        <Style x:Key="WindowStyle1" TargetType="{x:Type Window}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Window}">
                        <ContentPresenter/>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

@tonyhallett
Copy link
Author

tonyhallett commented Feb 12, 2025

Your changes do not account for the properties of a Window.

https://learn.microsoft.com/en-us/dotnet/api/system.windows.window.resizemode?view=netframework-4.8

CanResizeWithGrip. This option has the same functionality as CanResize, but adds a "resize grip" to the lower right corner of the window.

There is no resize grip to be displayed under any conditions in the control template that you are now showing.
Also the Window does have a Background and Border, as per the original documentation, that is now non existent.

The problem with the original documentation was that it was incomplete as it was referring to a resource that was not displayed Ǡ. I have shown you that resource.

Feel free to name the resource as you would like

( For the JetSystemColors from Aero just use SystemColors )

@tonyhallett
Copy link
Author

I have looked at the vs designer code and it looks like it should be reading from the directory
\DesignTools\SystemThemes\Wpf
within the vs installation.

Which should be aero2.normalcolor.xaml for windows OS >= Win 8.

    <ControlTemplate x:Key="WindowTemplateKey"
                     TargetType="{x:Type Window}">
        <Border Background="{TemplateBinding Background}"
                BorderBrush="{TemplateBinding BorderBrush}"
                BorderThickness="{TemplateBinding BorderThickness}">
            <Grid>
                <AdornerDecorator>
                    <ContentPresenter/>
                </AdornerDecorator>

                <ResizeGrip x:Name="WindowResizeGrip"
                            HorizontalAlignment="Right"
                            VerticalAlignment="Bottom"
                            Visibility="Collapsed"
                            IsTabStop="false"/>
            </Grid>
        </Border>
        <ControlTemplate.Triggers>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="Window.ResizeMode"
                               Value="CanResizeWithGrip"/>
                    <Condition Property="Window.WindowState"
                               Value="Normal"/>
                </MultiTrigger.Conditions>
                <Setter TargetName="WindowResizeGrip"
                        Property="Visibility"
                        Value="Visible"/>
            </MultiTrigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>


    <Style x:Key="{x:Type Window}"
           TargetType="{x:Type Window}">
        <Setter Property="Foreground"
                Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>
        <Setter Property="Background"
                Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Window}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                        <AdornerDecorator>
                            <ContentPresenter/>
                        </AdornerDecorator>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="Window.ResizeMode"
                     Value="CanResizeWithGrip">
                <Setter Property="Template"
                        Value="{StaticResource WindowTemplateKey}"/>
            </Trigger>
        </Style.Triggers>
    </Style>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-bug Problem with the content; needs to be fixed [org][type][category] dotnet-framework/svc in-pr okr-quality Pri1 High priority, do before Pri2 and Pri3 📌 seQUESTered Label to indicate an item has been imported. wpf/subsvc
Projects
Development

Successfully merging a pull request may close this issue.

2 participants