Với XAML sau, hàng dưới cùng sẽ ẩn khi bạn bỏ chọn hộp kiểm. Tất cả mọi thứ là tốt cho đến khi bạn thay đổi kích thước nó với gridsplitter. Sau đó kiểm tra/bỏ chọn hộp kiểm không làm gì cả. Cho rằng bộ chuyển đổi thiết lập chiều cao là 0 tôi dự kiến hàng ẩn. Chuyện gì vậy? Làm thế nào tôi có thể thiết lập lại chiều cao sau khi di chuyển bộ chia?Làm thế nào để đặt lại chiều cao hàng lưới sau khi sử dụng bộ tách?
<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>
Chuyển đổi:
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();
}
}
Bạn có thể đưa ra ví dụ không? Tôi không thể làm cho nó hoạt động được. – Manuel
@Manuel, tôi đã tạo ra thứ gì đó phù hợp với mình. – Phil