窗口在屏幕的时候使用WPF壳一体化库最大化 [英] Window out of the screen when maximized using WPF shell integration library

查看:116
本文介绍了窗口在屏幕的时候使用WPF壳一体化库最大化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 WPF壳一体化图书馆创建我的WPF应用程序自定义镶边。 所有这些都是好的,但是当最大化应用程序,6或7个像素都出了画面。

这是在code我使用:

 <风格的TargetType ={X:本地型:主窗口}>
        < setter属性=壳:WindowChrome.WindowChrome>
            < Setter.Value>
                <外壳:WindowChrome
                    ResizeBorderThickness =6
                    CaptionHeight =10
                    CornerRadius =0
                    GlassFrameThickness =1/>
            < /Setter.Value>
        < /二传手>
        < setter属性=模板>
            < Setter.Value>
                <的ControlTemplate的TargetType ={X:输入本地:主窗口}>
                    <电网>
                        &所述;边框了borderThickness =1BorderBrush =#389FD1背景=#389FD1>
                            <内容presenter保证金=0,22,0,0CONTENT ={TemplateBinding内容}/>
                        < /边框>
                        < StackPanel的方向=横向的Horizo​​ntalAlignment =右VerticalAlignment =热门>
                            <8的TextBlock文本={结合NombreUsuario}前景=白保证金=5,5,20,5不透明度= />
                            <按钮样式={的StaticResource的ImageButton}高度=20WIDTH =20保证金=0点击=WindowMinimize壳:WindowChrome.IsHitTestVisibleInChrome =真>
                                <图像高度=10WIDTH =10来源=/资源/图像/ minimize.png/>
                            < /按钮>
                            <按钮样式={的StaticResource的ImageButton}高度=20WIDTH =20保证金=0点击=WindowMaximizeRestore壳:WindowChrome.IsHitTestVisibleInChrome =真>
                                <图像高度=10WIDTH =10来源=/资源/图像/ maximize.png/>
                            < /按钮>
                            <按钮样式={的StaticResource的ImageButton}高度=20WIDTH =20保证金=0点击=WindowClose壳:WindowChrome.IsHitTestVisibleInChrome =真>
                                <图像高度=10WIDTH =10来源=/资源/图像/ close.png/>
                            < /按钮>
                        < / StackPanel的>

                    < /网格>
                < /控件模板>
            < /Setter.Value>
        < /二传手>
    < /样式和GT;
 

解决方案

视窗裁剪窗口的边缘时,它的最大化,以掩盖什么,通常是调整的边缘。你可以围绕这把窗口和内容之间的代理边框上,然后膨胀的厚度时,它的最大化。

我修改了附带的lib做到这一点的例子,相同的基本变化,可以对您的样本:

 <的ControlTemplate的TargetType ={X:类型本地:SelectableChromeWindow}>
  < BORDER BorderBrush =绿色>
    < Border.Style>
      <风格的TargetType ={X:边框类型}>
        < setter属性=了borderThickness值=0/>
        < Style.Triggers>
          < D​​ataTrigger绑定={结合的ElementName = ThisWindow,路径=的WindowState}值=最大化>
            < setter属性=了borderThicknessVALUE ={绑定源= {X:静态外壳:SystemParameters2.Current},路径= WindowResizeBorderThickness}/>
          < / DataTrigger>
        < /Style.Triggers>
      < /样式和GT;
    < /Border.Style>
    <电网[...] />
  < /边框>
< /控件模板>
 

我希望帮助,

I'm using the WPF Shell Integration Library to create a custom chrome of my wpf app. All is good, but when maximizing the app, 6 or 7 pixels are out of the screen.

This is the code I'm using:

<Style TargetType="{x:Type local:MainWindow}">
        <Setter Property="shell:WindowChrome.WindowChrome">
            <Setter.Value>
                <shell:WindowChrome
                    ResizeBorderThickness="6"
                    CaptionHeight="10"
                    CornerRadius="0"
                    GlassFrameThickness="1"/>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:MainWindow}">
                    <Grid>
                        <Border BorderThickness="1" BorderBrush="#389FD1" Background="#389FD1">
                            <ContentPresenter Margin="0,22,0,0" Content="{TemplateBinding Content}"/>
                        </Border>
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Top" >
                            <TextBlock Text="{Binding NombreUsuario}" Foreground="White" Margin="5,5,20,5" Opacity=".8" />
                            <Button Style="{StaticResource ImageButton}" Height="20" Width="20" Margin="0" Click="WindowMinimize" shell:WindowChrome.IsHitTestVisibleInChrome="True">
                                <Image Height="10" Width="10" Source="/Resources/Images/minimize.png" />
                            </Button>
                            <Button Style="{StaticResource ImageButton}" Height="20" Width="20" Margin="0" Click="WindowMaximizeRestore" shell:WindowChrome.IsHitTestVisibleInChrome="True" >
                                <Image Height="10" Width="10" Source="/Resources/Images/maximize.png" />
                            </Button>
                            <Button Style="{StaticResource ImageButton}" Height="20" Width="20" Margin="0" Click="WindowClose" shell:WindowChrome.IsHitTestVisibleInChrome="True">
                                <Image Height="10" Width="10" Source="/Resources/Images/close.png" />
                            </Button>
                        </StackPanel>

                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

解决方案

Windows crops the edges of the window when it's maximized to obscure what would normally be the resize edges. You can get around this by putting a proxy border between the window and your content and then inflate the thickness when it's maximized.

I modified the example that came with the lib to do this, the same basic change could be made to your sample:

<ControlTemplate TargetType="{x:Type local:SelectableChromeWindow}">
  <Border BorderBrush="Green">
    <Border.Style>
      <Style TargetType="{x:Type Border}">
        <Setter Property="BorderThickness" Value="0"/>
        <Style.Triggers>
          <DataTrigger Binding="{Binding ElementName=ThisWindow, Path=WindowState}" Value="Maximized">
            <Setter Property="BorderThickness" Value="{Binding Source={x:Static shell:SystemParameters2.Current}, Path=WindowResizeBorderThickness}"/>
          </DataTrigger>
        </Style.Triggers>
      </Style>
    </Border.Style>
    <Grid [...]/>
  </Border>
</ControlTemplate>

I hope that helps,

这篇关于窗口在屏幕的时候使用WPF壳一体化库最大化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆