0

In a WPF application the user can double click a line in a DataGrid to open a new page that contain tabs with grids - some of these have GridSplitters like this

Private Function CentreGrid() As Grid
    Try
        Dim vGrid As New Grid
        For i As Integer = 0 To 2
            Dim vCol As New ColumnDefinition
            If i = 1 Then
                vCol.Width = New GridLength(5, GridUnitType.Auto)
            End If
            vGrid.ColumnDefinitions.Add(vCol)
        Next

        Dim vLeftGrid As Grid = LeftGrid()
        Grid.SetColumn(vLeftGrid, 0)
        vGrid.Children.Add(vLeftGrid)

        Dim vGridSplitter As New GridSplitter
        With vGridSplitter
            .VerticalAlignment = Windows.VerticalAlignment.Stretch
            .HorizontalAlignment = Windows.HorizontalAlignment.Center
            .ResizeBehavior = GridResizeBehavior.PreviousAndNext
            .Background = New SolidColorBrush(Colors.Blue)
            .Width = 5
            .Margin = New Thickness(5)
        End With
        Grid.SetColumn(vGridSplitter, 1)
        vGrid.Children.Add(vGridSplitter)

        Dim vRightGrid As Grid = RightGrid()
        Grid.SetColumn(vRightGrid, 2)
        vGrid.Children.Add(vRightGrid)

        Return vGrid
    Catch ex As Exception
        EmailError(ex)
        Return Nothing
    End Try
End Function

As everything is generated dynamically from code-behind is there any method to get a handle on the relative grid position that has been changed by the user so that when the page is closed and another instance opened the GridSplitter can be in the same relative position that the user selected beforehand?

Thanks

gchq
  • 1,603
  • 2
  • 27
  • 52
  • I believe what you want is not where the gridsplitter is, but what is the width of grid columns are. Set them like they were before and the gridsplitter will be in the same place. If you absolutely want the location, take a look at [Get Absolute Position of element within the window in wpf](http://stackoverflow.com/questions/386731/get-absolute-position-of-element-within-the-window-in-wpf) – Pouya Abadi Jan 19 '17 at 02:24
  • Hi Pouya - yes you are correct, it is the grids either side of the splitter that I need to get a handle on. The problem is grids are not controls so once created I cannot easily return the current values like a static grid with a name. I guess drilling down through child elements of the main container might work – gchq Jan 19 '17 at 19:47

0 Answers0