开发者

How to get GridSplitter to move between extremes

I have a Gridsplitter in a vertical grid and ideally what would like to see two buttons in the GridSplitter. An up button would automatically move the splitter to the highest top position and a bottom button would move it all the way down. However, t开发者_运维技巧he GridSplitter cannot contain other items. Any thoughts on a way around this? I thought of just making a panel and then sandwiching it between two GridSplitters?


GridSplitter inherits from Control, so all you need to do is define a template for it that includes the two buttons:

<ControlTemplate x:Key="SplitterWithButtons" TargetType="{x:Type GridSplitter}">
  <Border BorderBrush="{TemplateBinding BorderBrush}"
          BorderThickness="{TemplateBinding BorderThickness}"
          Background="{TemplateBinding Background}">
    <DockPanel>
      <Button DockPanel.Dock="Left" Content="{StaticResource UpArrow}" Click="OnSplitterUpButton" />
      <Button DockPanel.Dock="Right" Content="{StaticResource DownArrow}" Click="OnSplitterDownButton" />
    </DockPanel>
  </Border>
</ControlTemplate>

...

<GridSplitter Template="{StaticResource SplitterWithButtons}" ... />

Inside your event handlers you can find the GridSplitter like this:

private void OnSplitterUpButton(object sender, RoutedEventArgs e)
{
  var splitter = ((Button)sender).TemplatedParent as GridSplitter;
  ...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜