3

I'm attempting to control the visibility of a PropertyDefinition in a Telerik RadPropertyGrid by binding to the property's Visibility attribute, but it appears as though the PropertyDefinition ignores changes to that attribute.

The control's XAML code is below. Note TestVis.

<Window x:Class="SettingsDialog"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
        Title="SettingsDialog"
        Height="500"
        Width="330">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <telerik:RadPropertyGrid
            Grid.Row="0"
            x:Name="PropertyGrid"
            AutoGeneratePropertyDefinitions="False"
            Item="{Binding}">
            <telerik:RadPropertyGrid.PropertyDefinitions>
                <telerik:PropertyDefinition
                    Binding="{Binding Setting1}"
                    DisplayName="Property 1"
                    Description=""Lorem ipsum dolor sit amet"
                    />
                <telerik:PropertyDefinition
                    Binding="{Binding Setting2}"
                    Visibility="{Binding TestVis}"
                    DisplayName="Property 2"
                    Description=""Lorem ipsum dolor sit amet"
                    />
            </telerik:RadPropertyGrid.PropertyDefinitions>
        </telerik:RadPropertyGrid>
    </Grid>
</Window>

The code-behind for this dialog is below.

using System.Windows;

public partial class SettingsDialog : Window
{
   private Visibility _TestVis;
   public Visibility TestVis
   {
      get { return _TestVis; }
      set
      {
         this._TestVis = value;
         NotifyPropertyChanged( "TestVis" );
      }
   }

   public bool Setting1 = { get; set; }
   public bool Setting2 = { get; set; }

   public SettingsDialog()
   {
      Setting1 = true;
      Setting2 = true;
      TestVis = Visibility.Collapsed;

      InitializeComponent();
   }
}

I would expect that this would cause "Property 2" to not be displayed, but there it is. What am I doing wrong?

user990423
  • 1,397
  • 2
  • 12
  • 32
Amelamise
  • 73
  • 6
  • I changed the `TestVis` assignment in the constructor to have a `Visibility` value instead of a Boolean. – Amelamise Sep 14 '15 at 17:58

2 Answers2

0

I think it is because your binding is inside RadPropertyGrid and this binding doesn't know there's a Property Named TestVis also you need a booleanConverter oterwise it doesn't work properly, But since you are binding item {binding}.

I think the RelativeSource is not neccessary

 Visibility="{Binding TestVis,
 RelativeSource={RelativeSource AncestorType={x:Typtelerik:RadPropertyGrid}}",
 Converter={StaticResource booleanToVisibilityConverter}}">>

Add this and it should work. and in your ressource dictionnary add reference to the converter

 <telerik:BooleanToVisibilityConverter x:Key="booleanToVisibilityConverter" />
Guillaume
  • 180
  • 1
  • 8
0

My solution unfortunately does not use binding. You'd have to specify a Name for each property you want to be able to hide.

<telerik:PropertyDefinition
    x:Name="Setting1PropertyDefinition"
    Binding="{Binding Setting1}"
    DisplayName="Property 1"
    Description=""Lorem ipsum dolor sit amet"
    />

Then in the code behind using the reference to your SettingsDialog instance:

dialog.Settings1PropertyDefinition.Visibility = Visibility.Collapsed;
E-rich
  • 9,243
  • 11
  • 48
  • 79