Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8548061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:24:29+00:00 2026-06-11T13:24:29+00:00

I have a WPF page, with a Grid on it. There are three rows.

  • 0

I have a WPF page, with a Grid on it.

There are three rows. Row 0 contains a GridView with Height="*". Row 1 contains a GridSplitter with Height="auto". Row 2 contains a details form with Height="2*".

Here’s the thing – I have a button that is supposed to toggle the visibility of the details form. And that works just fine. Except that it just hides the form in Row 2, it doesn’t expand the Grid in Row 0 to fill the space. What I want is for the button to toggle GridView in Row 0 to take up all the space, and then to toggle back to where things were.

Clearly playing around with the Visibility of the form inside the row won’t accomplish what I want.

But what do I need to be playing around with?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T13:24:30+00:00Added an answer on June 11, 2026 at 1:24 pm

    I had to introduce an Attached Dependency Property to handle this in my own application:

    <Grid c:GridSplitterController.Watch="{Binding ElementName=GS_DetailsView}">
        <Grid.RowDefinitions>
            <RowDefinition Height="1*" />
            <RowDefinition Height="200" />
        </Grid.RowDefinitions>
    
        <SomeControl Grid.Row="0" />
    
        <GridSplitter x:Name="GS_DetailsView"
                      Height="4"
                      Grid.Row="1"
                      VerticalAlignment="Top"
                      HorizontalAlignment="Stretch"
                      ResizeBehavior="PreviousAndCurrent"
                      ResizeDirection="Rows"
                      Visibility="{Binding ShowDetails,
                                           Converter={StaticResource boolvis}}" />
    
        <OtherControl Grid.Row="1"
                      Margin="0,4,0,0"
                      Visibility="{Binding ShowDetails,
                                           Converter={StaticResource boolvis}}" />
    </Grid>
    

    First define a suitable attached property on a DependencyObject:

    public static GridSplitter GetWatch(DependencyObject obj)
    {
        return (GridSplitter)obj.GetValue(WatchProperty);
    }
    
    public static void SetWatch(DependencyObject obj, GridSplitter value)
    {
        obj.SetValue(WatchProperty, value);
    }
    
    public static readonly DependencyProperty WatchProperty =
        DependencyProperty.RegisterAttached(
            "Watch",
            typeof(GridSplitter),
            typeof(DependencyObject),
            new UIPropertyMetadata(null, OnWatchChanged));
    

    Then listen for IsVisibleChanged:

    private static void OnWatchChanged(DependencyObject obj,
        DependencyPropertyChangedEventArgs e)
    {
        if (obj == null) return;
        if (obj is Grid)
        {
            var grid = obj as Grid;
            var gs = e.NewValue as GridSplitter;
            if (gs != null)
            {
                gs.IsVisibleChanged += (_sender, _e) =>
                    {
                        UpdateGrid(
                            grid,
                            (GridSplitter)_sender,
                            (bool)_e.NewValue,
                            (bool)_e.OldValue);
                    };
            }
        }
    }
    

    Once you are watching for these changes, you need to save or restore the GridLength values from the row or columns you are watching (for brevity I’m only including Rows):

    // Given: static Dictionary<DependencyObject, GridLength> oldValues;
    private static void UpdateGrid(Grid grid, GridSplitter gridSplitter, bool newValue, bool oldValue)
    {
        if (newValue)
        {
            // We're visible again
            switch (gridSplitter.ResizeDirection)
            {
            case GridResizeDirection.Columns:
                break;
            case GridResizeDirection.Rows:
                int ridx = (int)gridSplitter.GetValue(Grid.RowProperty);
                var prev = grid.RowDefinitions.ElementAt(GetPrevious(gridSplitter, ridx));
                var curr = grid.RowDefinitions.ElementAt(GetNext(gridSplitter, ridx));
                if (oldValues.ContainsKey(prev) && oldValues.ContainsKey(curr))
                {
                    prev.Height = oldValues[prev];
                    curr.Height = oldValues[curr];
                }
    
                break;
            }
        }
        else
        {
            // We're being hidden
            switch (gridSplitter.ResizeDirection)
            {
            case GridResizeDirection.Columns:
                break;
            case GridResizeDirection.Rows:
                int ridx = (int)gridSplitter.GetValue(Grid.RowProperty);
                var prev = grid.RowDefinitions.ElementAt(GetPrevious(gridSplitter, ridx));
                var curr = grid.RowDefinitions.ElementAt(GetNext(gridSplitter, ridx));
                switch (gridSplitter.ResizeBehavior)
                {
                    // Naively assumes only one type of collapsing!
                    case GridResizeBehavior.PreviousAndCurrent:
                        oldValues[prev] = prev.Height;
                        prev.Height = new GridLength(1.0, GridUnitType.Star);
    
                        oldValues[curr] = curr.Height;
                        curr.Height = new GridLength(0.0);
                        break;
                }
                break;
            }
        }
    }
    

    All that is left is a suitable implementation of GetPrevious and GetNext:

    private static int GetPrevious(GridSplitter gridSplitter, int index)
    {
        switch (gridSplitter.ResizeBehavior)
        {
            case GridResizeBehavior.PreviousAndNext:
            case GridResizeBehavior.PreviousAndCurrent:
                return index - 1;
            case GridResizeBehavior.CurrentAndNext:
                return index;
            case GridResizeBehavior.BasedOnAlignment:
            default:
                throw new NotSupportedException();
        }
    }
    
    private static int GetNext(GridSplitter gridSplitter, int index)
    {
        switch (gridSplitter.ResizeBehavior)
        {
            case GridResizeBehavior.PreviousAndCurrent:
                return index;
            case GridResizeBehavior.PreviousAndNext:
            case GridResizeBehavior.CurrentAndNext:
                return index + 1;
            case GridResizeBehavior.BasedOnAlignment:
            default:
                throw new NotSupportedException();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Silverlight 4 Page. The page contains a single grid, with three
I have two pages in WPF. Page A contains all of my code. Page
I have a WebBrowser control hosted on a WPF page. I'm wondering if there
I'm trying to integrate a WinForms Form inside a WPF XAML page. I have
I have a WPF page that has 2 ContentControls on it. Both of the
I have a web page that I display in a WPF WebBrowser control within
I have WPF Application where I have One main form and other user controls
I have WPF Form which has many buttons with the same code. Appearance of
I have a WPF DataGrid that increases in height when I add data to
I have a WPF page (as my View) in an MVVM model. The View

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.