これはデバッグが面白かったです。ウィンドウのスタイルにはバグがあります。システムがIsGlassEnabled == true
(Win7 Aeroテーマではtrue
になります)と定義されている場合、ウィンドウはMicrosoft.Windows.Shell.WindowChrome(Microsoft.Windows.Shellアセンブリ)を使用して、枠線とウィンドウの上部ボタンを描画します。このWindowChromeはと組み合わせて8,30,8,8
に設定されたGlassFrameThickness
プロパティがBottom
に設定されています。
何が起こるするためAllowsTransparency == true
のガラス境界は透明であるが、WindowChrome
は、このようにビューからResizeGrip
を切断、NonClientFrameEdges="Bottom"
を定義するためのウィンドウがまだ全体ウィンドウサイズから、その厚さを「切断する」ことです。
画面上にウィンドウをドラッグすると、これが表示されます。ResizeGrip
がちらついて表示されます。
:我々は
NonClientFrameEdges="None"
(または
GlassFrameThickness = 0
あるいはその両方)を使用して新しい
WindowChrome
を定義し、
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>
DataTrigger
は、元のスタイルとほぼ同じですが、修正は1つしかありません。私は、セッターにWindowChromeをコメントしました。
MultiDataTrigger
が私の追加です。彼らはプロパティの値をチェックし、値がの場合は元の値、true
の場合はNonClientFrameEdges="None"
の値を返します(GlassFrameThickness = 0
でもかまいません)。
注:このソリューションは、エッジを使用してウィンドウのサイズを変更する機能を削除します。ウィンドウのサイズ変更は、ResizeGrip
によってのみ行われます。