Quantcast
Channel: Telerik Forums RSS
Viewing all articles
Browse latest Browse all 84751

Incorrect editors when switching PropertySetMode

$
0
0

I'm experiencing some odd behavior when changing the PropertySetMode at runtime. 

 

I have two object types: MyTestClass1 and MyTestClass2. MyTestClass1 has a writeable property IntProp and MyTestClass2 has a readonly property IntProp. If I start in Intersection mode with Item = List<Object> { myTestClass1Obj1, myTestClass1Obj2 } everything works properly. If I then change to PropertySetMode None with Item = myTestClass2Obj, the editor for IntProp will be writeable even though IntProp on myTestClass2Obj has no public setter.

 

See runnable test case below. I am running 2015.2.728

<Windowx:Class="WpfApplication1.MainWindow"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"       
        Title="MainWindow"Height="350"Width="525">
    <Grid>
    <StackPanelOrientation="Vertical">
      <ButtonClick="ButtonBase_OnClick">Change to mode none</Button>
      <telerik:RadPropertyGridx:Name="rpg"/>
    </StackPanel>
  </Grid>
</Window>

usingSystem;
usingSystem.Collections.Generic;
usingSystem.Windows;
usingSystem.Windows.Controls;
usingSystem.Windows.Data;
usingSystem.ComponentModel;
usingSystem.Collections.ObjectModel;
usingSystem.Text.RegularExpressions;
usingSystem.ComponentModel.DataAnnotations;
usingTelerik.Windows.Controls.Data.PropertyGrid;
 
namespaceWpfApplication1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    publicpartialclassMainWindow : Window
    {
      privatereadonlyMyTestClass test;
    privatereadonlyMyTestClass test2;
    privatereadonlyMyTestClass2 test3;
 
    publicMainWindow()
        {
            InitializeComponent();
            rpg.AutoGeneratingPropertyDefinition += newEventHandler<Telerik.Windows.Controls.Data.PropertyGrid.AutoGeneratingPropertyDefinitionEventArgs>(rpg_AutoGeneratingPropertyDefinition);
 
      // test data. IntProp is has a public setter
      test = newMyTestClass() { StringProp = "91das", RequiredField = "abc", IntProp = 10, DateTimeProp = newDateTime(1920, 2, 21) };
      test2 = newMyTestClass() { StringProp = "91das", RequiredField = "abc", IntProp = 10, DateTimeProp = newDateTime(1920, 2, 21) };
 
      // test data. IntProp is read only (no public setter)
      test3 = newMyTestClass2() { StringProp = "91das", RequiredField = "abc", DateTimeProp = newDateTime(1920, 2, 21) };
 
      rpg.Item = newList<Object> {test, test2};
      rpg.PropertySetMode = PropertySetOperation.Intersection;
        }
 
        voidrpg_AutoGeneratingPropertyDefinition(objectsender, Telerik.Windows.Controls.Data.PropertyGrid.AutoGeneratingPropertyDefinitionEventArgs e)
        {
            (e.PropertyDefinition.Binding asBinding).ValidatesOnDataErrors = true;
            (e.PropertyDefinition.Binding asBinding).NotifyOnValidationError = true;
            (e.PropertyDefinition.Binding asBinding).ValidatesOnExceptions = true;
        }
 
        privateObservableCollection<ValidationError> results;
 
        publicObservableCollection<ValidationError> Results
        {
            get
            {
                if(this.results == null)
                {
                    this.results = newObservableCollection<ValidationError>();
                }
                returnresults;
            }
        }
     
    privatevoidButtonBase_OnClick(objectsender, RoutedEventArgs e)
    {
      rpg.PropertySetMode = PropertySetOperation.None;
      rpg.Item = test3;
      // the property grid will now allow setting of test3.IntProp even though there is
      // no public setter
    }
  }
 
 
    publicclassMyTestClass : IDataErrorInfo, INotifyPropertyChanged
    {
         
        privateintintVar;
        privatestringrequiredField;
 
        publicintIntProp
        {
            get{ returnintVar; }
            set
            {
                intVar = value;
                this.OnPropertyChanged("IntProp");
            }
        }
 
        [Required(ErrorMessage = "This field is Required.")]
        publicstringRequiredField
        {
            get{ returnrequiredField; }
            set
            {
                requiredField = value;
                ValidateProperty("RequiredField", value);
                this.OnPropertyChanged("RequiredField");
            }
        }
 
        privatestringstringVar;
 
        publicstringStringProp
        {
            get{ returnstringVar; }
            set
            {
                stringVar = value;
                this.OnPropertyChanged("StringProp");
            }
        }
 
        privateDateTime dateTimeVar;
 
        publicDateTime DateTimeProp
        {
            get{ returndateTimeVar; }
            set
            {
                dateTimeVar = value;
                this.OnPropertyChanged("DateTimeProp");
            }
        }
 
        [Browsable(false)]
        publicstringError
        {
            get{ returnstring.Empty; }
        }
 
        publicstringthis[stringcolumnName]
        {
            get
            {
                if(columnName == "IntProp")
                {
                    returnthis.IntProp < 100 && this.IntProp > 0 ? string.Empty : "Value should be in the range of (0, 100)";
                }
                if(columnName == "StringProp")
                {
                    returnthis.StringProp != null&& Regex.IsMatch(this.StringProp, @"^[0-9]+[\p{L}]*") ? string.Empty : @"Value should math the regex: ^[0-9]+[\p{L}]*";
                }
                if(columnName == "DateTimeProp")
                {
                    returnthis.DateTimeProp.Year > 1900 ? string.Empty : "Date should be after 1/1/1900";
                }
                returnstring.Empty;
            }
        }
 
        protectedvoidOnPropertyChanged(stringname)
        {
            if(this.PropertyChanged != null)
            {
                this.PropertyChanged(this, newPropertyChangedEventArgs(name));
            }
        }
 
        publiceventPropertyChangedEventHandler PropertyChanged;
 
        publicvoidValidateProperty(stringpropName, objectvalue)
        {
            var result = newList<System.ComponentModel.DataAnnotations.ValidationResult>();
            Validator.TryValidateProperty(value, newValidationContext(this, null, null) { MemberName = propName }, result);
 
            if(result.Count > 0)
            {
               thrownewValidationException(result[0].ErrorMessage);
            }
        }
    }
 
 
  publicclassMyTestClass2 : IDataErrorInfo, INotifyPropertyChanged
  {
 
    privateintintVar;
    privatestringrequiredField;
 
    publicintIntProp { get; } = 12;
 
    [Required(ErrorMessage = "This field is Required.")]
    publicstringRequiredField
    {
      get{ returnrequiredField; }
      set
      {
        requiredField = value;
        ValidateProperty("RequiredField", value);
        this.OnPropertyChanged("RequiredField");
      }
    }
 
    privatestringstringVar;
 
    publicstringStringProp
    {
      get{ returnstringVar; }
      set
      {
        stringVar = value;
        this.OnPropertyChanged("StringProp");
      }
    }
 
    privateDateTime dateTimeVar;
 
    publicDateTime DateTimeProp
    {
      get{ returndateTimeVar; }
      set
      {
        dateTimeVar = value;
        this.OnPropertyChanged("DateTimeProp");
      }
    }
 
    [Browsable(false)]
    publicstringError
    {
      get{ returnstring.Empty; }
    }
 
    publicstringthis[stringcolumnName]
    {
      get
      {
        if(columnName == "IntProp")
        {
          returnthis.IntProp < 100 && this.IntProp > 0 ? string.Empty : "Value should be in the range of (0, 100)";
        }
        if(columnName == "StringProp")
        {
          returnthis.StringProp != null&& Regex.IsMatch(this.StringProp, @"^[0-9]+[\p{L}]*") ? string.Empty : @"Value should math the regex: ^[0-9]+[\p{L}]*";
        }
        if(columnName == "DateTimeProp")
        {
          returnthis.DateTimeProp.Year > 1900 ? string.Empty : "Date should be after 1/1/1900";
        }
        returnstring.Empty;
      }
    }
 
    protectedvoidOnPropertyChanged(stringname)
    {
      if(this.PropertyChanged != null)
      {
        this.PropertyChanged(this, newPropertyChangedEventArgs(name));
      }
    }
 
    publiceventPropertyChangedEventHandler PropertyChanged;
 
    publicvoidValidateProperty(stringpropName, objectvalue)
    {
      var result = newList<System.ComponentModel.DataAnnotations.ValidationResult>();
      Validator.TryValidateProperty(value, newValidationContext(this, null, null) { MemberName = propName }, result);
 
      if(result.Count > 0)
      {
        thrownewValidationException(result[0].ErrorMessage);
      }
    }
  }
}
 

 

dafadsf


Viewing all articles
Browse latest Browse all 84751

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>