26

我想设置我的 GridSplitter 的样式,比如在其上添加点(如在http://msdn.microsoft.com/en-us/library/aa970265.aspx上找到)。

我还想在 mouseOver 上更改 gridsplitter 颜色,或应用 Aero 主题。

<Style x:Key="GridSplitterStyle1" TargetType="{x:Type GridSplitter}">
  <Setter Property="Background"
          Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
  <Setter Property="PreviewStyle">
    <Setter.Value>
      <Style>
        <Setter Property="Control.Template">
          <Setter.Value>
            <ControlTemplate>
              <Rectangle Fill="#80000000"/>
            </ControlTemplate>
          </Setter.Value>
        </Setter>
      </Style>
    </Setter.Value>
  </Setter>
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="{x:Type GridSplitter}">
        <Border Background="{TemplateBinding Background}"
                BorderBrush="{TemplateBinding BorderBrush}"
                BorderThickness="{TemplateBinding BorderThickness}"/>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

<!--Theme-->
<ResourceDictionary.MergedDictionaries>
  <ResourceDictionary 
   Source="/RibbonControlsLibrary;component/Themes/Office2007Blue.xaml" />
</ResourceDictionary.MergedDictionaries>

<GridSplitter x:Name="gridSplitterTreeNodes" Width="10"
              BorderThickness="1,0" Cursor="SizeWE"
              RenderTransformOrigin="-1.2,0.507" ShowsPreview="True" 
              Style="{DynamicResource GridSplitterStyle1}">
  <GridSplitter.Background>
    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
      <GradientStop Color="#FFE3EFFF" Offset="0"/>
      <GradientStop Color="#FFAFD2FF" Offset=".45"/>
    </LinearGradientBrush>
  </GridSplitter.Background>
</GridSplitter>
4

5 回答 5

40

主要是为了我自己未来的参考,这里是一个垂直的网格分割器,它有一个圆形的按钮(但对鼠标悬停没有正确的反应):

<GridSplitter Grid.Column="1" VerticalAlignment="Stretch" HorizontalAlignment="Center" Width="8">
    <GridSplitter.Template>
        <ControlTemplate TargetType="{x:Type GridSplitter}">
            <Grid>
                <Button Content="⁞" />
                <Rectangle Fill="#00FFFFFF" />
            </Grid>
        </ControlTemplate>
    </GridSplitter.Template>
</GridSplitter>

水平分割器可以只使用“····”作为按钮的内容。

于 2011-07-04T07:16:22.230 回答
18
<GridSplitter x:Name="gridSplitterTreeNodes" Width="5" BorderThickness="1,0" 
     Cursor="SizeWE" RenderTransformOrigin="-1.2,0.507" ShowsPreview="True"
     Style="{DynamicResource GridSplitterStyle1}">
  <GridSplitter.Background>
    <ImageBrush ImageSource="Images\gripDots.png" TileMode="FlipXY" 
                Stretch="UniformToFill"/>
  </GridSplitter.Background>
</GridSplitter>

您还可以从 Msnd Microsoft 保存图像以获得相同的效果,更多信息

于 2009-11-10T11:35:16.410 回答
4

在不丢失鼠标事件的情况下,将“抓手”按钮/图形添加到 GridSplitter 的另一种方法是在拆分器顶部使用一个简单的标签。

    <GridSplitter Grid.Column="1" Width="5" HorizontalAlignment="Stretch" Background="Gray"/>

    <Label Grid.Column="1" Content="⁞" Foreground="White" VerticalAlignment="Center" FontSize="26" FontWeight="Bold" IsHitTestVisible="False"/>

确保 GridSplitter 和 Label 在同一列中,并且在 Label 中设置了 IsHitTestVisible=False。

于 2016-03-17T09:50:35.313 回答
1

对于不同类型的样式,您可以执行以下操作。

产生一个很好的重叠样式。Gridsplitter 将左右内容重叠。

<Grid>
     <Grid.ColumnDefinitions>
         <ColumnDefinition Width="*"/>
         <ColumnDefinition Width="1"/>
         <ColumnDefinition Width="*"/>
     </Grid.ColumnDefinitions>

     <Border Grid.Column="0" Background="#777"/>

     <GridSplitter
         Grid.Column="1"
         HorizontalAlignment="Stretch" 
         ResizeDirection="Columns"
         ResizeBehavior="PreviousAndNext"
         Panel.ZIndex="2">
           <GridSplitter.Template>

               <ControlTemplate TargetType="{x:Type GridSplitter}">

                   <Grid>
                        <Rectangle IsHitTestVisible="False" Fill="Black"/>
                        <Border
                           Background="White"
                           Width="25" Height="25" c 
                           CornerRadius="25" Margin="-13 0">
                           <Path Stroke="Black" StrokeThickness="0.5" Width="17" Height="7" Data="m 4.4549201,1048.4664 -4.33056515,1.9095 4.33056515,1.9094 0,-3.8189 z m 3.0901599,0 0,3.8189 4.330565,-1.9094 -4.330565,-1.9095 z m -3.2239449,0.2053 0,3.4083 -3.86518514,-1.7041 3.86518514,-1.7042 z m 3.3577349,0 3.865185,1.7042 -3.865185,1.7041 0,-3.4083 z" Stretch="Fill"/>
                        </Border>
                   </Grid>

                </ControlTemplate>

                </GridSplitter.Template>

     </GridSplitter>

     <Border Grid.Column="2" Background="#777"/>

</Grid>

样本输出

于 2020-11-06T21:31:49.687 回答
0

针对 Burton Radons 的回答,我个人更喜欢造型:

<GridSplitter
  Width="8"
  HorizontalAlignment="Stretch"
  VerticalAlignment="Stretch">

  <GridSplitter.Template>
    <ControlTemplate TargetType="{x:Type GridSplitter}">
      <Grid>
        <TextBlock
          HorizontalAlignment="Center"
          VerticalAlignment="Center"
          Text="⁞&quot; />
        <Rectangle Fill="#00FFFFFF" />
      </Grid>
    </ControlTemplate>
  </GridSplitter.Template>
</GridSplitter>

这种实现产生了相同的美学效果,同时也保持了功能性。

于 2020-09-12T02:32:50.530 回答