This project has moved. For the latest updates, please go here.

PropertyGrid style suggestion

Jan 26, 2012 at 3:08 PM

In PropertyGrid there are the two bindings ShowSearchBox and ShowSortOptions. If you set both to false the PropertyGrid looks a bit odd because there is still the "parent" grid visible (around line 397 in Generic.xaml).

I fixed that with a MultiBinding and a converter:

 

 

                            <Grid Grid.Row="1" Margin="4,0,4,4">
                                <Grid.Visibility>
                                    <MultiBinding Converter="{StaticResource OrMultiVisibilityConverter}">
                                        <Binding Path="ShowSortOptions" RelativeSource="{RelativeSource TemplatedParent}"/>
                                        <Binding Path="ShowSearchBox" RelativeSource="{RelativeSource TemplatedParent}" />
                                    </MultiBinding>
                                </Grid.Visibility>
 

    
using System;
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Data

public class OrMultiVisibilityConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            bool visible = values.OfType<bool>().Aggregate(false, (current, value) => current || value);

            return visible ? Visibility.Visible : Visibility.Collapsed;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            return new[] {DependencyProperty.UnsetValue};
        }
    }

 

Jan 28, 2012 at 12:23 AM

Thanks for the tip.