2017-02-15 79 views
0

我正在使用包含網格分隔符的深色背景在WPF中創建應用程序。網格分離器必須與ShowPreview = True一起使用。網格分割器的預覽「陰影」與我的背景非常融合,所以我想編輯它的樣式。我找不到有關如何更改預覽樣式的任何內容。我希望看到我可以改變的畫筆屬性。有任何想法嗎?WPF:如何使用ShowsPreview設置GridSplitter的預覽樣式

<GridSplitter 
    Width="2" 
    Background="{DynamicResource BaseBorderBrush}" 
    ResizeBehavior="CurrentAndNext" 
    ShowsPreview="True"> 
</GridSplitter> 

回答

0

使用its Style和改變這一部分:<Setter Property="Background" Value="Red" />。請注意,我將其更改爲紅色。

<GridSplitter 
     HorizontalAlignment="Right" VerticalAlignment="Stretch" Width="50" ResizeBehavior="CurrentAndNext" ShowsPreview="True"> 
     <GridSplitter.Style> 
      <Style TargetType="controls:GridSplitter"> 
       <Setter Property="Background" Value="#FFFFFFFF" /> 
       <Setter Property="IsTabStop" Value="true" /> 
       <Setter Property="HorizontalAlignment" Value="Right" /> 
       <Setter Property="PreviewStyle"> 
        <Setter.Value> 
         <Style TargetType="Control"> 
          <!-- Background --> 
          <Setter Property="Background" Value="Red" /> 
          <Setter Property="Template"> 
           <Setter.Value> 
            <ControlTemplate TargetType="Control"> 
             <Grid x:Name="Root" Opacity=".5"> 
              <Rectangle Fill="{TemplateBinding Background}" /> 

              <!-- Horizontal Template --> 
              <Grid x:Name="HorizontalTemplate" Height="6"> 
               <!-- Just show the faint gray grid splitter rectangle with no other details --> 
              </Grid> 

              <!-- Vertical Template --> 
              <Grid x:Name="VerticalTemplate" Visibility="Collapsed" Width="6"> 
               <!-- Just show the faint gray grid splitter rectangle with no other details --> 
              </Grid> 

             </Grid> 
            </ControlTemplate> 
           </Setter.Value> 
          </Setter> 
         </Style> 
        </Setter.Value> 
       </Setter> 
       <Setter Property="Template"> 
        <Setter.Value> 
         <ControlTemplate TargetType="controls:GridSplitter"> 
          <Grid x:Name="Root" IsHitTestVisible="{TemplateBinding IsEnabled}"> 

           <!-- VSM --> 
           <vsm:VisualStateManager.VisualStateGroups> 
            <vsm:VisualStateGroup x:Name="CommonStates"> 
             <vsm:VisualState x:Name="Normal" /> 
             <vsm:VisualState x:Name="MouseOver" /> 
             <vsm:VisualState x:Name="Disabled"> 
              <Storyboard> 
               <DoubleAnimation Storyboard.TargetName="Root" Storyboard.TargetProperty="Opacity" To="0.5" Duration="0" /> 
              </Storyboard> 
             </vsm:VisualState> 
            </vsm:VisualStateGroup> 
            <vsm:VisualStateGroup x:Name="FocusStates"> 
             <vsm:VisualStateGroup.Transitions> 
              <vsm:VisualTransition GeneratedDuration="0" /> 
             </vsm:VisualStateGroup.Transitions> 
             <vsm:VisualState x:Name="Unfocused" /> 
             <vsm:VisualState x:Name="Focused"> 
              <Storyboard> 
               <DoubleAnimation Storyboard.TargetName="FocusVisual" Storyboard.TargetProperty="Opacity" To="1" Duration="0" /> 
              </Storyboard> 
             </vsm:VisualState> 
            </vsm:VisualStateGroup> 
           </vsm:VisualStateManager.VisualStateGroups> 

           <!-- Background --> 
           <Rectangle Fill="{TemplateBinding Background}" StrokeThickness="0" /> 

           <!-- Horizontal Template --> 
           <Grid x:Name="HorizontalTemplate" Height="10"> 
            <StackPanel Height="6" VerticalAlignment="Center"> 
             <Rectangle Height="1" Margin="1" Width="10" StrokeThickness="0" Fill="#FF868686" /> 
             <Rectangle Height="1" Margin="1" Width="10" StrokeThickness="0" Fill="#FF868686" /> 
            </StackPanel> 
           </Grid> 

           <!-- Vertical Template --> 
           <Grid x:Name="VerticalTemplate" Visibility="Collapsed" Width="10"> 
            <StackPanel Width="6" VerticalAlignment="Center" Orientation="Horizontal"> 
             <Rectangle Width="1" Margin="1" Height="10" StrokeThickness="0" Fill="#FF868686" /> 
             <Rectangle Width="1" Margin="1" Height="10" StrokeThickness="0" Fill="#FF868686" /> 
            </StackPanel> 
           </Grid> 

           <!-- Focus Visual --> 
           <Rectangle x:Name="FocusVisual" Stroke="#FF6DBDD1" StrokeThickness="1" Opacity="0" IsHitTestVisible="false" /> 
          </Grid> 
         </ControlTemplate> 
        </Setter.Value> 
       </Setter> 
      </Style> 
     </GridSplitter.Style> 
    </GridSplitter> 

不要忘記在XAML中的XML命名空間的映射:

xmlns:vsm="clr-namespace:System.Windows;assembly=PresentationFramework" 
xmlns:controls="clr-namespace:System.Windows.Controls;assembly=PresentationFramework" 
+0

您可能還需要改變混濁的''<電網X:「5" NAME = 「根」 不透明度=> '' – Ron