使用以下 XAML,当您取消选中该复选框时,底行将隐藏。一切都很好,直到你用 gridsplitter 调整它的大小。然后选中/取消选中复选框不会做任何事情。鉴于转换器将高度设置为 0,我希望该行隐藏。这是怎么回事?移动分离器后如何重置高度?
<Grid>
<Grid.Resources>
<m:CheckedToLengthConverter x:Key="checkedToLengthConverter" />
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="3*" />
<RowDefinition Height="{Binding Mode=OneWay, ElementName=ShowBottomCheckBox, Path=IsChecked, Converter={StaticResource checkedToLengthConverter}, ConverterParameter=2}" />
</Grid.RowDefinitions>
<Border Background="Blue" />
<CheckBox Name="ShowBottomCheckBox" IsChecked="True" />
<GridSplitter HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Height="5" />
<Border Background="Red" Grid.Row="1" />
</Grid>
转换器:
public class CheckedToLengthConverter: IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if ((bool)value)
return new GridLength(int.Parse(parameter.ToString()), GridUnitType.Star);
return new GridLength(0, GridUnitType.Pixel);
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}