0
votes

Disclosure:

I am new to WPF, about a week into it.

Problem:

I am trying to modify the behavior of a GridSplitter, to make it snap to interesting positions, to show a label (that follows the splitter) with current position, to have a context menu driven from said label, etc. I have prototyped all of this successfully on one gridsplitter in one simple test application, with a combination of XAML and some code behind.

Of note is that because the GridSplitter can't host content, I placed the label in the same grid cell as the splitter so that they move together.

So far so good....

Now I wish to replicate my work so that I can use my new GridSplitter functionality in place of the native control in many locations, and furthermore, I wish to have two variants, a horizontal and a vertical. Sounds like inheritance...create a subclass derived from GridSplitter and add in the additional functionality. But all of the reading I have done leaves me wondering how to go about this, and if this is even possible without starting over again and building my own GridSplitter from scratch?

Ideas welcome. Until then I will resume the fetal position.

Thanks

3
BTW, post your current code and XAML, and if you can a screenshot of what you need - Federico Berasategui
Let's just say I wish to add a text box that says "Hello, World!" that moves around with the GridSplitter, and encapsulate that functionality for re-use :) - 2stroke

3 Answers

1
votes

This answer might help you resolve your issue: How to make GridSplitter to "snap" into another element?

By subscribing to the GridSplitterDragCompleted event, you can insert your logic to snap to "interesting" positions.

0
votes

You should

  1. create a new control derived from GridSplitter.
  2. subscribe to DragCompleted event to implement snapping functionality like DLeh mentioned.
  3. add a few new properties for Label , ContextMenu etc.
  4. supply a style for your new control.
0
votes

This answers how to place content in the splitter

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="40" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions> 
    <Button Grid.Row="0" Content="Row 0" Background="Orange"/>
    <!--<GridSplitter Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Stretch" Height="20" Background="Purple"/>-->
    <GridSplitter Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Stretch">
        <GridSplitter.Template>
            <ControlTemplate TargetType="{x:Type GridSplitter}">
                <TextBlock Text="TextBlock splitter" Background="Yellow" FontWeight="Bold"/>
            </ControlTemplate>
        </GridSplitter.Template>
    </GridSplitter>
    <Button Grid.Row="2" Content="Row 0" Background="Salmon"/>
</Grid>