카테고리 없음
[wpf] Gridsplitter가 이동할 때 WPF 그리드 확장기 목록보기가 공간을 채 웁니다.
필살기쓰세요
2021. 1. 25. 13:15
이것이 필요한지 확인하십시오.
<Window ...>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Expander Grid.Row="0" Collapsed="Expander_Collapsed_1">
<ListView x:Name="Lv1"/>
</Expander>
<GridSplitter Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Top" ShowsPreview="true" ResizeDirection="Rows" Height="5" Background="#FFB82424"/>
<Expander Grid.Row="2" Collapsed="Expander_Collapsed_1">
<ListView x:Name="Lv2" Grid.Row="0"/>
</Expander>
<GridSplitter Grid.Row="3" HorizontalAlignment="Stretch" VerticalAlignment="Top" ShowsPreview="true" ResizeDirection="Rows" Height="5" Background="#FFC51A1A"/>
</Grid>
</Window>
코드 :
private void Expander_Collapsed_1(object sender, RoutedEventArgs e)
{
DependencyObject dobj = VisualTreeHelper.GetParent(sender as Expander);
while (!(dobj is Grid))
dobj = VisualTreeHelper.GetParent(dobj);
int i = Grid.GetRow(sender as Expander);
Grid grd = dobj as Grid;
grd.RowDefinitions[i].Height = GridLength.Auto;
}
출처
https://stackoverflow.com/questions/39917247