JD2022-TU1/main/tools/apps/FrameworkTest/PropertyGridTest/SampleObject.cs

456 lines
12 KiB
C#

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Media;
using Color = System.Windows.Media.Color;
namespace FrameworkTest.PropertyGridTest
{
public class ObservableList<T> : ObservableCollection<T>
{
}
public class SampleObject : INotifyPropertyChanged
{
public SampleObject()
{
String = "John";
Int = 12;
Double = 185;
Color = Colors.AliceBlue;
DateTime = DateTime.Now;
_listOfPersons = new List<Person>();
Person p1 = new Person() { FirstName = "Jim", SurName = "Raynor" };
Person p2 = new Person() { FirstName = "Sarah", SurName = "Kerrigan" };
p1.Spouse = p2;
p2.Spouse = p1;
_person = p1;
_listOfPersons.Add(p1);
_listOfPersons.Add(p2);
_listOfStrings = new List<string>();
_listOfStrings.AddRange(new string[] { "action", "aventure", "strategy", "rpg" });
_listOfInt = new List<int>();
_listOfInt.AddRange(new int[] { 15, 21, -25, 1, 500, 50 });
_arrayOfPersons = new Person[] { p1, p2 };
_dictionaryOfPersons = new Dictionary<Person, Person>();
_dictionaryOfPersons[p1] = p1;
_dictionaryOfPersons[p2] = p2;
_dictionaryOfBools = new Dictionary<Person, bool>();
_dictionaryOfBools[p1] = true;
_dictionaryOfBools[p2] = false;
_linkedListOfPersons = new LinkedList<Person>();
_linkedListOfPersons.AddLast(p1);
_linkedListOfPersons.AddLast(p2);
_linkedListOfBool = new LinkedList<bool>();
_linkedListOfBool.AddLast(true);
_linkedListOfBool.AddLast(false);
_linkedListOfBool.AddLast(true);
_linkedListOfBool.AddLast(true);
_privateProperty = "this is private";
_protectedProperty = "this is protected";
_readOnlyProperty = "this is readonly";
}
public enum MyEnum
{
EnumValue1,
EnumValue2,
EnumValue3,
EnumValue4
}
[Flags]
public enum MyFlags
{
None = 0x0,
FlagValue1 = 0x1,
FlagValue2 = 0x2,
FlagValue3 = 0x4,
FlagValue4 = 0x8
}
private string _string;
[Category("Base")]
[Browsable(true)]
public string String
{
get { return _string; }
set
{
_string = value;
OnPropertyChanged("String");
}
}
private string _privateProperty;
[Category("Misc")]
[Browsable(true)]
private string PrivateProperty
{
get { return _privateProperty; }
set
{
_privateProperty = value;
OnPropertyChanged("PrivateProperty");
}
}
private string _protectedProperty;
[Category("Misc")]
[Browsable(true)]
protected string ProtectedProperty
{
get { return _protectedProperty; }
set
{
_protectedProperty = value;
OnPropertyChanged("ProtectedProperty");
}
}
private int _int;
[Category("Base")]
[Browsable(true)]
public int Int
{
get { return _int; }
set
{
_int = value;
OnPropertyChanged("Int");
}
}
private byte _byte;
[Category("Base")]
[Browsable(true)]
public byte Byte
{
get { return _byte; }
set
{
_byte = value;
OnPropertyChanged("Byte");
}
}
private double _double;
[Category("Base")]
[Browsable(true)]
[DefaultValue(15d)]
public double Double
{
get { return _double; }
set
{
_double = value;
OnPropertyChanged("Double");
}
}
private bool _bool;
[Category("Base")]
[Browsable(true)]
public bool Boolean
{
get { return _bool; }
set
{
_bool = value;
OnPropertyChanged("Boolean");
}
}
private MyEnum _enum;
[Category("Base")]
[Browsable(true)]
public MyEnum Enum
{
get { return _enum; }
set
{
_enum = value;
OnPropertyChanged("Enum");
}
}
private MyFlags _flag;
[Category("Base")]
[Browsable(true)]
public MyFlags Flag
{
get { return _flag; }
set
{
_flag = value;
OnPropertyChanged("Flag");
}
}
private Color _color;
[Category("Useful types")]
[Browsable(true)]
public Color Color
{
get { return _color; }
set
{
_color = value;
OnPropertyChanged("Color");
}
}
private DateTime _datetime;
[Category("Useful types")]
[Browsable(true)]
public DateTime DateTime
{
get { return _datetime; }
set
{
_datetime = value;
OnPropertyChanged("DateTime");
}
}
private TimeSpan _timespan;
[Category("Useful types")]
[Browsable(true)]
public TimeSpan TimeSpan
{
get { return _timespan; }
set
{
_timespan = value;
OnPropertyChanged("DateTime");
}
}
private List<string> _listOfStrings;
[Category("Collections")]
[Browsable(true)]
public List<string> ListOfStrings
{
get { return _listOfStrings; }
set
{
_listOfStrings = value;
OnPropertyChanged("ListOfStrings");
}
}
private List<Person> _listOfPersons;
[Category("Collections")]
[Browsable(true)]
public List<Person> ListOfPersons
{
get { return _listOfPersons; }
set
{
_listOfPersons = value;
OnPropertyChanged("ListOfPersons");
}
}
private LinkedList<Person> _linkedListOfPersons;
[Category("Collections")]
[Browsable(true)]
public LinkedList<Person> LinkedListOfPersons
{
get { return _linkedListOfPersons; }
set
{
_linkedListOfPersons = value;
OnPropertyChanged("LinkedListOfPersons");
}
}
private LinkedList<bool> _linkedListOfBool;
[Category("Collections")]
[Browsable(true)]
public LinkedList<bool> LinkedListOfBool
{
get { return _linkedListOfBool; }
set
{
_linkedListOfBool = value;
OnPropertyChanged("LinkedListOfBool");
}
}
private Person[] _arrayOfPersons;
[Category("Collections")]
[Browsable(true)]
public Person[] ArrayOfPersons
{
get { return _arrayOfPersons; }
set
{
_arrayOfPersons = value;
OnPropertyChanged("ArrayOfPersons");
}
}
private Dictionary<Person, bool> _dictionaryOfBools;
[Category("Collections")]
[Browsable(true)]
public Dictionary<Person, bool> DictionaryOfBools
{
get { return _dictionaryOfBools; }
set
{
_dictionaryOfBools = value;
OnPropertyChanged("DictionaryOfBools");
}
}
private Dictionary<Person, Person> _dictionaryOfPersons;
[Category("Collections")]
[Browsable(true)]
public Dictionary<Person, Person> DictionaryOfPersons
{
get { return _dictionaryOfPersons; }
set
{
_dictionaryOfPersons = value;
OnPropertyChanged("DictionaryOfPersons");
}
}
private List<int> _listOfInt;
[Category("Collections")]
[Browsable(true)]
public List<int> ListOfInt
{
get { return _listOfInt; }
set
{
_listOfInt = value;
OnPropertyChanged("ListOfInt");
}
}
private Person _person;
[Category("Base")]
[Browsable(true)]
public Person Person
{
get { return _person; }
set
{
_person = value;
OnPropertyChanged("Person");
}
}
private readonly string _readOnlyProperty;
[Category("Misc")]
[Browsable(true)]
public string ReadOnlyProperty
{
get { return _readOnlyProperty; }
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
}
public class SampleObjectA : SampleObject
{
public SampleObjectA()
{
_privateProperty = "this is private";
}
private Color _specificColor;
[Category("ZSpecific")]
[Browsable(true)]
public Color SpecificColor
{
get { return _specificColor; }
set
{
_specificColor = value;
OnPropertyChanged("SpecificColor");
}
}
private string _privateProperty;
[Category("Misc")]
[Browsable(true)]
private string PrivateProperty
{
get { return _privateProperty; }
set
{
_privateProperty = value;
OnPropertyChanged("PrivateProperty");
}
}
}
public class SampleObjectB : SampleObject
{
public SampleObjectB()
{
_privateProperty = "this is private";
}
private int _specificInt;
[Category("ZSpecific")]
[Browsable(true)]
public int SpecificInt
{
get { return _specificInt; }
set
{
_specificInt = value;
OnPropertyChanged("SpecificInt");
}
}
private double _specificDouble;
[Category("ZSpecific")]
[Browsable(true)]
public double SpecificDouble
{
get { return _specificDouble; }
set
{
_specificDouble = value;
OnPropertyChanged("SpecificDouble");
}
}
private string _privateProperty;
[Category("Misc")]
[Browsable(true)]
private string PrivateProperty
{
get { return _privateProperty; }
set
{
_privateProperty = value;
OnPropertyChanged("PrivateProperty");
}
}
}
}