![]() Public class BooleanConverter : IValueConverter As you can see, even though the splitter isn't visible, the user can still access it.Īdd a new file Extensions.cs to host the behavior. Now, press the TAB key once and use the ARROW UP key to move the GridSplitter. So let's add some custom behavior to sync the collapsed rows with their controls.įirst, run the example using the code above, then collapse the bottom rows by checking the checkbox. Only then it will be able to take over the remaining space.Īs mentioned in his post, the controls that are contained by collapsed rows will still be focusable, allowing users to access them when they shouldn't.Īdmittedly, it could be a pain setting the visibility for all controls by hand, especially for large XAMLs. This to ensure the star sized row has a size when you put the splitter all the way up and toggle visibility. You should have either a MaxHeight on the collapsable row (the third one in our example) or a MinHeight on the non-collapsable row (the first) adjacent to the splitter. Row.Height = collapsed ? new GridLength(0) : row.cachedHeight If(d is CollapsibleRow row & e.NewValue is bool collapsed) Private static void OnCollapsedChanged(DependencyObject d, DependencyPropert圜hangedEventArgs e) After that, you no longer need converters or to toggle visibility of contained controls.ĬollapsibleRow public class CollapsibleRow : RowDefinitionĭependencyProperty.Register("Collapsed", typeof(bool), typeof(CollapsibleRow), new PropertyMetadata(false, OnCollapsedChanged)) Public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)Īll you need is something to cache the height(s) of the visible row. Return collapsed ? Visibility.Collapsed : Visibility.Visible If (values.Length > 1 & values is bool invert & invert) If (values.Length > 0 & values is bool collapsed) Public object Convert(object values, Type targetType, object parameter, CultureInfo culture) Public class BoolVisibilit圜onverter : IMultiValueConverter Set => SetValue(InvertCollapsedProperty, value) Get => (bool)GetValue(InvertCollapsedProperty) Set => SetValue(CollapsedProperty, value) Get => (bool)GetValue(CollapsedProperty) Public static readonly DependencyProperty InvertCollapsedProperty =ĭependencyProperty.Register("InvertCollapsed", typeof(bool), typeof(CollapsibleRow), new PropertyMetadata(INVERT_COLLAPSED_DEFAULT)) Public static readonly DependencyProperty CollapsedProperty =ĭependencyProperty.Register("Collapsed", typeof(bool), typeof(CollapsibleRow), new PropertyMetadata(COLLAPSED_DEFAULT)) Private const bool INVERT_COLLAPSED_DEFAULT = false Private const bool COLLAPSED_DEFAULT = false Public class CollapsibleRow : RowDefinition Propert圜hanged?.Invoke(this, new Propert圜hangedEventArgs(propertyName)) Private void OnPropert圜hanged( string propertyName = null) Public event Propert圜hangedEventHandler Propert圜hanged Public partial class MainWindow : INotifyPropert圜hanged My question is what can be done differently so that it does not matter about the size of the rows or if MinHeight / MaxHeight are set, it is just able to collapse the rows? I tried to fix this by adding setters for these properties in the data trigger but it did not fix it. Similarly, if MinHeight or MaxHeight is set on any of the rows that are collapsed, it no longer collapses the row at all. Instead, there is just a white gap where the rows used to be. ![]() However, when it is less than half way, the rows still collapse, but the first row does not expand. In the example below, this works perfectly when the grid splitter is over half way up the window. It does it by using a converter and a datatrigger in a style to set the height of the row to 0. I have created a custom WPF element extended from RowDefinition that should collapse rows in a grid when the Collapsed property of the element is set to True.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |