Ejemplo n.º 1
0
        public void AdvancedPropertyDescriptorConstructionTestWithFuncs()
        {
            PropertyBag bag = new PropertyBag();
            // add some property specifications.
            var property1 = new PropertySpecification("Property 1", typeof(string), "Cat1", "Prop1 desc", "Foo");

            // make readonly
            property1.Attributes.Add(ReadOnlyAttribute.Yes);
            bag.PropertySpecifications.Add(property1);

            // add expanding property
            var property2 = new PropertySpecification("Picture", typeof(Image), "Some Category", "This is a sample description.");

            property2.Attributes.Add(new TypeConverterAttribute(typeof(ExpandableObjectConverter)));
            bag.PropertySpecifications.Add(property2);

            // custom editor
            var property3 = new PropertySpecification("Source folder", typeof(string), "OutputFolders", "The output folder for the sourcecode", "c:\\temp");

            property3.Attributes.Add(new EditorAttribute(typeof(System.Windows.Forms.Design.FolderNameEditor), typeof(System.Drawing.Design.UITypeEditor)));
            property3.ConvertEmptyStringToNull = true;
            bag.PropertySpecifications.Add(property3);

            // use value list
            var property4 = new PropertySpecification("PickAValue", typeof(string), "Cat1", "A property which value has to be picked from a list", "One");

            property4.TypeConverterType = typeof(PropertySpecificationValuesListTypeConverter);
            property4.ValueList.AddRange(new[] { "One", "Two", "Three", "Many" });
            bag.PropertySpecifications.Add(property4);

            var property5 = new PropertySpecification("EnumValue", typeof(ConsoleColor), "Cat1", "Enum property to see that values are converted back/forth to int");

            bag.PropertySpecifications.Add(property5);

            // value list to store values in
            Dictionary <string, object> values = new Dictionary <string, object>();

            // func setting so values get store inside the dictionary and also retrieved from it. Console write added to see what happens when you bind
            // a windows forms propertygrid to a bag: many many redundant calls to the getters/setters occur.
            bag.ValueGetterFunc = (s) =>
            {
                var v = values.GetValue(s);
                Console.WriteLine("Get: {0} : {1}", s, v ?? "<null>");
                return(v);
            };
            bag.ValueSetterFunc = (s, v) =>
            {
                values[s] = v;
                Console.WriteLine("Set: {0} : {1}", s, v ?? "<null>");
            };

            // open a testform which binds the bag to the propertygrid. Editing values will store the values in the dictionary, default values are
            // not in the dictionary.
            using (TestForm f = new TestForm(bag))
            {
                f.ShowDialog();
            }
        }
Ejemplo n.º 2
0
		public void SimplePropertyDescriptorConstructionTest()
		{
			PropertyBag bag = new PropertyBag();
			// add some property specifications. 
			bag.PropertySpecifications.Add(new PropertySpecification("Property 1", typeof(string), "Cat1", "Prop1 desc", "Foo"));
			bag.PropertySpecifications.Add(new PropertySpecification("Property 2", typeof(string), "Cat1", "Prop2 desc", "Bar"));
			bag.PropertySpecifications.Add(new PropertySpecification("Property 3", typeof(string), "Cat2", "Prop3 desc", string.Empty));

			// open a testform which binds the propertybag to a property grid. There's no value store so edited values are not stored. Just
			// to show the categorization etc.
			using(TestForm f = new TestForm(bag))
			{
				f.ShowDialog();
			}
		}
Ejemplo n.º 3
0
        public void SimplePropertyDescriptorConstructionTest()
        {
            PropertyBag bag = new PropertyBag();

            // add some property specifications.
            bag.PropertySpecifications.Add(new PropertySpecification("Property 1", typeof(string), "Cat1", "Prop1 desc", "Foo"));
            bag.PropertySpecifications.Add(new PropertySpecification("Property 2", typeof(string), "Cat1", "Prop2 desc", "Bar"));
            bag.PropertySpecifications.Add(new PropertySpecification("Property 3", typeof(string), "Cat2", "Prop3 desc", string.Empty));

            // open a testform which binds the propertybag to a property grid. There's no value store so edited values are not stored. Just
            // to show the categorization etc.
            using (TestForm f = new TestForm(bag))
            {
                f.ShowDialog();
            }
        }
Ejemplo n.º 4
0
        public void AdvancedPropertyDescriptorConstructionTestWithEvents()
        {
            PropertyBag bag = new PropertyBag();
            // add some property specifications.
            var property1 = new PropertySpecification("Property 1", typeof(string), "Cat1", "Prop1 desc", "Foo");

            // make readonly
            property1.Attributes.Add(ReadOnlyAttribute.Yes);
            bag.PropertySpecifications.Add(property1);

            // add expanding property
            var property2 = new PropertySpecification("Picture", typeof(Image), "Some Category", "This is a sample description.");

            property2.Attributes.Add(new TypeConverterAttribute(typeof(ExpandableObjectConverter)));
            bag.PropertySpecifications.Add(property2);

            // custom editor
            var property3 = new PropertySpecification("Source folder", typeof(string), "OutputFolders", "The output folder for the sourcecode", "c:\\temp");

            property3.Attributes.Add(new EditorAttribute(typeof(System.Windows.Forms.Design.FolderNameEditor), typeof(System.Drawing.Design.UITypeEditor)));
            bag.PropertySpecifications.Add(property3);

            // use value list
            var property4 = new PropertySpecification("PickAValue", typeof(string), "Cat1", "A property which value has to be picked from a list");

            property4.TypeConverterType = typeof(PropertySpecificationValuesListTypeConverter);
            property4.ValueList.AddRange(new[] { "One", "Two", "Three", "Many" });
            bag.PropertySpecifications.Add(property4);

            // value list to store values in
            Dictionary <string, object> values = new Dictionary <string, object>();

            // event handler binding so values get store inside the dictionary and also retrieved from it.
            bag.GetValue += (sender, e) => { e.Value = values.GetValue(e.Property.Name); };
            bag.SetValue += (sender, e) => { values[e.Property.Name] = e.Value; };

            // open a testform which binds the bag to the propertygrid. Editing values will store the values in the dictionary, default values are
            // not in the dictionary.
            using (TestForm f = new TestForm(bag))
            {
                f.ShowDialog();
            }
        }
Ejemplo n.º 5
0
		public void AdvancedPropertyDescriptorConstructionTestWithEvents()
		{
			PropertyBag bag = new PropertyBag();
			// add some property specifications. 
			var property1 = new PropertySpecification("Property 1", typeof(string), "Cat1", "Prop1 desc", "Foo");
			// make readonly
			property1.Attributes.Add(ReadOnlyAttribute.Yes);
			bag.PropertySpecifications.Add(property1);

			// add expanding property
			var property2 = new PropertySpecification("Picture", typeof(Image), "Some Category", "This is a sample description.");
			property2.Attributes.Add(new TypeConverterAttribute(typeof(ExpandableObjectConverter)));
			bag.PropertySpecifications.Add(property2);

			// custom editor
			var property3 = new PropertySpecification("Source folder", typeof(string), "OutputFolders", "The output folder for the sourcecode", "c:\\temp");
			property3.Attributes.Add(new EditorAttribute(typeof(System.Windows.Forms.Design.FolderNameEditor), typeof(System.Drawing.Design.UITypeEditor)));
			bag.PropertySpecifications.Add(property3);

			// use value list
			var property4 = new PropertySpecification("PickAValue", typeof(string), "Cat1", "A property which value has to be picked from a list");
			property4.TypeConverterType = typeof(PropertySpecificationValuesListTypeConverter);
			property4.ValueList.AddRange(new[] { "One", "Two", "Three", "Many" });
			bag.PropertySpecifications.Add(property4);

			// value list to store values in
			Dictionary<string, object> values = new Dictionary<string, object>();

			// event handler binding so values get store inside the dictionary and also retrieved from it. 
			bag.GetValue += (sender, e) => { e.Value = values.GetValue(e.Property.Name); };
			bag.SetValue += (sender, e) => { values[e.Property.Name] = e.Value; };
			
			// open a testform which binds the bag to the propertygrid. Editing values will store the values in the dictionary, default values are
			// not in the dictionary.
			using(TestForm f = new TestForm(bag))
			{
				f.ShowDialog();
			}
		}
Ejemplo n.º 6
0
		public void AdvancedPropertyDescriptorConstructionTestWithFuncs()
		{
			PropertyBag bag = new PropertyBag();
			// add some property specifications. 
			var property1 = new PropertySpecification("Property 1", typeof(string), "Cat1", "Prop1 desc", "Foo");
			// make readonly
			property1.Attributes.Add(ReadOnlyAttribute.Yes);
			bag.PropertySpecifications.Add(property1);

			// add expanding property
			var property2 = new PropertySpecification("Picture", typeof(Image), "Some Category", "This is a sample description.");
			property2.Attributes.Add(new TypeConverterAttribute(typeof(ExpandableObjectConverter)));
			bag.PropertySpecifications.Add(property2);

			// custom editor
			var property3 = new PropertySpecification("Source folder", typeof(string), "OutputFolders", "The output folder for the sourcecode", "c:\\temp");
			property3.Attributes.Add(new EditorAttribute(typeof(System.Windows.Forms.Design.FolderNameEditor), typeof(System.Drawing.Design.UITypeEditor)));
			property3.ConvertEmptyStringToNull = true;
			bag.PropertySpecifications.Add(property3);

			// use value list
			var property4 = new PropertySpecification("PickAValue", typeof(string), "Cat1", "A property which value has to be picked from a list", "One");
			property4.TypeConverterType = typeof(PropertySpecificationValuesListTypeConverter);
			property4.ValueList.AddRange(new[] { "One", "Two", "Three", "Many" });
			bag.PropertySpecifications.Add(property4);

			var property5 = new PropertySpecification("EnumValue", typeof(ConsoleColor), "Cat1", "Enum property to see that values are converted back/forth to int");
			bag.PropertySpecifications.Add(property5);

			// value list to store values in
			Dictionary<string, object> values = new Dictionary<string, object>();

			// func setting so values get store inside the dictionary and also retrieved from it. Console write added to see what happens when you bind
			// a windows forms propertygrid to a bag: many many redundant calls to the getters/setters occur.
			bag.ValueGetterFunc = (s) =>
									{
										var v = values.GetValue(s);
										Console.WriteLine("Get: {0} : {1}", s, v ?? "<null>");
										return v;
									};
			bag.ValueSetterFunc = (s, v) =>
									{
										values[s] = v;
										Console.WriteLine("Set: {0} : {1}", s, v ?? "<null>");
									};

			// open a testform which binds the bag to the propertygrid. Editing values will store the values in the dictionary, default values are
			// not in the dictionary.
			using(TestForm f = new TestForm(bag))
			{
				f.ShowDialog();
			}
		}