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?
I had to introduce an Attached Dependency Property to handle this in my own application:
First define a suitable attached property on a
DependencyObject:Then listen for
IsVisibleChanged:Once you are watching for these changes, you need to save or restore the
GridLengthvalues from the row or columns you are watching (for brevity I’m only including Rows):All that is left is a suitable implementation of
GetPreviousandGetNext: