Mig*_*uel 3 wpf xaml wpf-controls ribboncontrolslibrary
我有一个RibbonWindow,我的WindowStyle被设置为None,所以我无法理解的是Grip发生了什么调整窗口的大小?!即使我的控件的底部部分的边距设置为0也会被隐藏......这是一种奇怪的行为.
但是如果我改变控件的底部边距就可以了,但无论如何都看不到Grip,可能是因为部分客户区隐藏了......
我不得不说,如果有一个WPF窗口,这不会发生,它只发生在RibbonWindow上.我正在使用RibbonWindow,因为Ribbon在适当的窗口中具有其他外观.
那么我该怎么做才能解决Grip的问题呢?
我的一些代码......
<rib:RibbonWindow x:Class="MyApp.Views.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:rib="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
AllowsTransparency="True"
Background="Transparent"
Height="750"
ResizeMode="CanResizeWithGrip"
Width="1000"
WindowStartupLocation="CenterScreen"
WindowStyle="None">
<Grid Margin="0, 0, 0, 20">
<Border Background="Black"
CornerRadius="5"
Opacity="0.5"/>
</Grid>
</rib:RibbonWindow>
Run Code Online (Sandbox Code Playgroud)
提前致谢!
这对调试很有吸引力.事实证明,窗口的样式有一个错误:如果系统被定义为IsGlassEnabled == true(在Win7 Aero主题中使用它true),那么窗口依赖于Microsoft.Windows.Shell.WindowChrome(从Microsoft.Windows.Shell程序集)到绘制窗口的边框和顶部按钮; 并且此WindowChrome的GlassFrameThickness属性设置为8,30,8,8与NonClientFrameEdgesset to 组合Bottom.
会发生的是,由于AllowsTransparency == true玻璃边框是透明的,但窗口仍然从整个窗口大小"切割"其厚度,因为WindowChrome定义NonClientFrameEdges="Bottom",从而切断了ResizeGrip视图.
如果您(疯狂地)将窗口拖到屏幕上,您可以看到这一点 - 您将看到ResizeGrip闪烁.
为了解决这个问题,我们需要定义一个新的WindowChrome有NonClientFrameEdges="None"(或GlassFrameThickness = 0或两者),并将其分配到窗口,只有当IsGlassEnabled == true && AllowsTransparency == true(我使用App.xaml中定义的应用程序资源,仅定义NonClientFrameEdges="None"):
1. Add these namespaces to App.xaml:
xmlns:ribbon="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
xmlns:ribbonPrimitives="clr-namespace:Microsoft.Windows.Controls.Ribbon.Primitives;assembly=RibbonControlsLibrary"
xmlns:shell="clr-namespace:Microsoft.Windows.Shell;assembly=Microsoft.Windows.Shell"
2. Add these resources:
<ribbonPrimitives:RibbonWindowSmallIconConverter x:Key="RibbonWindowSmallIconConverter" />
<shell:WindowChrome x:Key="WindowChromeWithGlassAndTransparency"
NonClientFrameEdges="None" />
<Style x:Key="MyStyle"
TargetType="{x:Type ribbon:RibbonWindow}">
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Path=IsGlassEnabled, Source={x:Static shell:SystemParameters2.Current}}"
Value="True" />
<Condition Binding="{Binding AllowsTransparency, RelativeSource={RelativeSource Mode=Self}}"
Value="False" />
</MultiDataTrigger.Conditions>
<Setter Property="shell:WindowChrome.WindowChrome"
Value="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type ribbon:Ribbon}, ResourceId=WindowChromeAeroWithGlass}}" />
</MultiDataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Path=IsGlassEnabled, Source={x:Static shell:SystemParameters2.Current}}"
Value="True" />
<Condition Binding="{Binding AllowsTransparency, RelativeSource={RelativeSource Mode=Self}}"
Value="True" />
</MultiDataTrigger.Conditions>
<Setter Property="shell:WindowChrome.WindowChrome"
Value="{DynamicResource WindowChromeWithGlassAndTransparency}" />
</MultiDataTrigger>
<DataTrigger Binding="{Binding Path=IsGlassEnabled, Source={x:Static shell:SystemParameters2.Current}}"
Value="True">
<!--This is the original setter of the chrome that makes all the trouble-->
<!--<Setter Property="shell:WindowChrome.WindowChrome"
Value="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type ribbon:Ribbon}, ResourceId=WindowChromeAeroWithGlass}}" />-->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ribbon:RibbonWindow}">
<Grid>
<Border Name="PART_ClientAreaBorder"
Background="{TemplateBinding Control.Background}"
BorderBrush="{TemplateBinding Control.BorderBrush}"
BorderThickness="{TemplateBinding Control.BorderThickness}"
Margin="{Binding Path=WindowNonClientFrameThickness, Source={x:Static shell:SystemParameters2.Current}}" />
<Border BorderThickness="{Binding Path=(shell:WindowChrome.WindowChrome).ResizeBorderThickness, RelativeSource={RelativeSource TemplatedParent}}">
<Grid>
<Image Name="PART_Icon"
shell:WindowChrome.IsHitTestVisibleInChrome="True"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Source="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Icon, Converter={StaticResource RibbonWindowSmallIconConverter }}"
Width="{Binding Path=SmallIconSize.Width, Source={x:Static shell:SystemParameters2.Current}}"
Height="{Binding Path=SmallIconSize.Height, Source={x:Static shell:SystemParameters2.Current}}" />
<AdornerDecorator>
<ContentPresenter Name="PART_RootContentPresenter" />
</AdornerDecorator>
<ResizeGrip Name="WindowResizeGrip"
shell:WindowChrome.ResizeGripDirection="BottomRight"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Visibility="Collapsed"
IsTabStop="False" />
</Grid>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Value="{x:Null}"
Property="Icon">
<Setter TargetName="PART_Icon"
Property="Source"
Value="/RibbonControlsLibrary;component/Images/GlassyDefaultSystemIcon.png" />
</Trigger>
<Trigger Property="WindowState"
Value="Maximized">
<Setter TargetName="PART_Icon"
Property="Margin"
Value="0,2,0,0" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="ResizeMode"
Value="CanResizeWithGrip" />
<Condition Property="WindowState"
Value="Normal" />
</MultiTrigger.Conditions>
<Setter TargetName="WindowResizeGrip"
Property="Visibility"
Value="Visible" />
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
3. In your window use the new style:
<rib:RibbonWindow ....
Style="{StaticResource MyStyle}">
....
</rib:RibbonWindow>
Run Code Online (Sandbox Code Playgroud)
在DataTrigger几乎是从原有的风格,只有一个修改:我评论了WindowChrome的制定者.
这MultiDataTrigger是我的补充.他们检查AllowsTransparency属性的值并应用正确的WindowChrome:如果值为,则为原始值;如果值为,则false应用NonClientFrameEdges="None"(还可以使用GlassFrameThickness = 0)true.
注意:此解决方案删除了使用边缘调整窗口大小的功能,窗口的大小调整仅由ResizeGrip.
| 归档时间: |
|
| 查看次数: |
1888 次 |
| 最近记录: |