2011-10-30 1 views
3

내 WindowStyle이 None으로 설정된 RibbonWindow가있어서 이해할 수없는 것은 그립에서 창 크기를 조정 한 것입니다. 내 컨트롤의 마진을 0으로 설정하더라도 맨 아래 부분은 숨겨집니다 ... 이상한 행동입니다. ...WPF RibbonWindow가 창 크기를 조절하기 위해 그립을 표시하지 않습니다.

을 내가 괜찮아 컨트롤의 아래쪽 여백을 변경할 수 있지만 그립은 아마 클라이언트 영역의 일부가 숨겨져 있기 때문에, 어쨌든 볼 수없는 경우

는하지만이 경우, 말을 WPF Window를 가지고 있는데, 이것은 일어나지 않습니다. RibbonWindow에서만 발생합니다. 그리고 리본이 적절한 창에서 다른 모양을 가지기 때문에 나는 RibbonWindow를 사용하고 있습니다.

그럼 그립으로 문제를 해결하려면 어떻게해야합니까? 사전에

내 코드의 일부

...

<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> 

감사합니다!

답변

7

디버깅이 흥미 롭습니다. 창 스타일에 버그가 있음을 알았습니다. 시스템이 IsGlassEnabled == true (Win7 Aero 테마로 만들면 true이됩니다)으로 정의 된 경우 Microsoft.Windows.Shell.WindowChrome (Microsoft.Windows.Shell 어셈블리)를 사용하여 창 테두리와 위쪽 단추를 그립니다. 이 WindowChrome의 GlassFrameThickness 속성은 과 조합하여 8,30,8,8Bottom으로 설정됩니다. 어떻게됩니까

때문에 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은 원래 스타일과 거의 동일하며 수정 사항이 하나뿐입니다. 설정기에 WindowChrome에 대한 댓글을 달았습니다.

MultiDataTrigger을 추가했습니다. 그들은 AllowsTransparency 속성의 값을 확인하고 오른쪽 WindowChrome을 적용합니다 : 값이 false 인 경우 NonClientFrameEdges="None" 인 경우 true 인 경우 을 대신 사용할 수도 있습니다.

참고 :이 솔루션은 가장자리를 사용하여 창의 크기를 조정하는 기능을 제거하고 창 크기는 ResizeGrip으로 만 조정됩니다.

관련 문제