Maximization of the custom window crops the content

gokul krish 21 Reputation points
2023-06-05T03:38:07.7666667+00:00

Created a custom window and given content in it. But maimizing the window through dragging it to the top , crops its content.

 <Style  TargetType="{x:Type local:Window1}">
                
                <Setter Property="Background" Value="AliceBlue"/>
                <Setter Property="BorderBrush" Value="LightSteelBlue"/>
                <Setter Property="BorderThickness" Value="0"/>
               
                <Setter Property="WindowChrome.WindowChrome">
                    <Setter.Value>
                        <WindowChrome  CornerRadius="0"  CaptionHeight="90" GlassFrameThickness="0">

                        </WindowChrome>
                    </Setter.Value>
                </Setter>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ContentControl}">
                            <AdornerDecorator>
                                <DockPanel Focusable="False" LastChildFill="True" >
                                    <Border Name="FloatWindowOutBorder"  Focusable="False"
						BorderBrush="{TemplateBinding BorderBrush}"
						BorderThickness="{TemplateBinding BorderThickness}"
						Background="{TemplateBinding Background}" >
                                        <Border.Style>
                                            <Style TargetType="{x:Type Border}">
                                                <Setter Property="BorderThickness" Value="0"/>
                                            </Style>
                                        </Border.Style>
                                        <Grid >
                                            
                                            <ContentPresenter Name="ContentPresenter"  
										  ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" 
										  Content="{TemplateBinding ContentControl.Content}" />
                                           
                                        </Grid>
                                    </Border>
                                </DockPanel>
                            </AdornerDecorator>

                        </ControlTemplate>

                    </Setter.Value>
                </Setter>
            </Style>


Developer technologies Windows Presentation Foundation
Developer technologies C#
{count} votes

Accepted answer
  1. Hui Liu-MSFT 48,676 Reputation points Microsoft External Staff
    2023-06-06T06:38:26.7233333+00:00

    Hi,@gokul krish. You could trigger the Margin of Border when the window is maximized to achieve the effect.

     <Style  TargetType="{x:Type local:Window1}">
    
                <Setter Property="Background" Value="AliceBlue"/>
                <Setter Property="BorderBrush" Value="LightSteelBlue"/>
                <Setter Property="BorderThickness" Value="0"/>
                
    
                <Setter Property="WindowChrome.WindowChrome">
                    <Setter.Value>
                        <WindowChrome  CornerRadius="0" CaptionHeight="90" GlassFrameThickness="0">
    
                        </WindowChrome>
                    </Setter.Value>
                </Setter>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ContentControl}">
                            <AdornerDecorator>
                                <DockPanel Focusable="False" LastChildFill="True" >
                                    <Border x:Name="FloatWindowOutBorder"  Focusable="False"
    						BorderBrush="{TemplateBinding BorderBrush}"
    						BorderThickness="{TemplateBinding BorderThickness}"
    						Background="{TemplateBinding Background}" >
                                        <Border.Style>
                                            <Style TargetType="{x:Type Border}">
                                                <Setter Property="BorderThickness" Value="0"/>
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=Window}, Path=WindowState}" Value="Maximized">
                                                        <Setter Property="Margin" Value="10" />
                                                        <Setter Property="BorderThickness" Value="0" />
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </Border.Style>
                                        <Grid >
                                            <ContentPresenter Name="ContentPresenter"  
                                                          ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
                                                          Content="{TemplateBinding ContentControl.Content}"
                                                         />
                                            
    
                                        </Grid>
                                    </Border>
                                </DockPanel>
                            </AdornerDecorator>
                           
                        </ControlTemplate>
    
                    </Setter.Value>
                </Setter>
                
            </Style>
    
    
    

    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.