Reputation: 2230
How can I hide the last two rows after resizing of splitter? When last two rows are hidden, the webBrowser should fill all the area.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="5" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<WebBrowser Name="webBrowser" />
<GridSplitter Grid.Row="1" ResizeDirection="Rows"
ResizeBehavior="PreviousAndNext" Width="Auto" Height="5"
HorizontalAlignment="Stretch"
Visibility="...">
</GridSplitter>
<c:MyControl Grid.Row="2" Visibility="..." />
</Grid>
Upvotes: 4
Views: 3712
Reputation: 2230
Quick fix of this issue:
public class HideableGridSplitter : GridSplitter
{
private GridLength height;
public HideableGridSplitter()
{
this.IsVisibleChanged += HideableGridSplitter_IsVisibleChanged;
}
void HideableGridSplitter_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
Grid parent = base.Parent as Grid;
if (parent == null)
return;
int rowIndex = Grid.GetRow(this);
if (rowIndex + 1 >= parent.RowDefinitions.Count)
return;
var lastRow = parent.RowDefinitions[rowIndex + 1];
if (this.Visibility == Visibility.Visible)
lastRow.Height = height;
else
{
height = lastRow.Height;
lastRow.Height = new GridLength(0);
}
}
}
Upvotes: 7
Reputation: 132558
Make a trigger on MyControl.ActualHeight. If 0, set visibility to collapsed
<DataTrigger Binding="{Binding ElementName=MyControl, Path=ActualHeight}" Value=0>
<Setter Property="Visibility" Value="Collapsed" />
</DataTrigger>
Upvotes: -1