|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionThis article is on sorting and globalization of properties in a Features:
It's easy to use and has ways to modify the place it looks for resources. BackgroundI ripped code from two projects, fused and improved them. The sorting idea was ripped from Paul Tingey, his Using the codeThe example below basically shows most of the possibilities: using System;
using System.ComponentModel;
using PropertyGridUtils;
namespace MyNameSpace
{
[TypeConverter(typeof(PropertiesDeluxeTypeConverter))]
class SomeClassWithProperties {
string lastName = "Zeeuw";
string occupation = "Software engineer";
int dynamicProperty = 3;
string dynamicPropertyDisplayName = "Dynamic property";
bool dynamicPropertyIsVisible = true;
bool dynamicPropertyIsReadOnly = false;
string propertyWithResourcesElseWhere = "Dummy";
SomeClassWithProperties child;
// DisplayName and Description are gotten from resource file
// MyNameSpace.SomeClassWithProperties.resources.
[PropertyOrder(0)]
[GlobalizedProperty(CategoryId = "GlobalCategory")]
public string LastName {
get {
return lastName;
}
}
// DisplayName and Description are gotten from resource file
// MyNameSpace.SomeClassWithProperties.resources.
[PropertyOrder(1)]
[GlobalizedProperty(CategoryId = "GlobalCategory")]
public string Occupation {
get {
return occupation;
}
}
// Behaviour of this property is partially defined runtime.
[PropertyOrder(2)]
[Description("This property is partially dynamic.")]
[PropertyAttributesProvider("DynamicPropertyAttributesProvider")]
public int DynamicProperty {
get {
return dynamicProperty;
}
set {
dynamicProperty = value;
}
}
public void DynamicPropertyAttributesProvider(PropertyAttributes attributes) {
attributes.DisplayName = dynamicPropertyDisplayName;
attributes.IsReadOnly = dynamicPropertyIsReadOnly;
attributes.IsBrowsable = dynamicPropertyIsVisible;
}
[PropertyOrder(3)]
[DisplayName("Dynamic property display name")]
public string DynamicPropertyDisplayName {
get {
return dynamicPropertyDisplayName;
}
set {
dynamicPropertyDisplayName = value;
}
}
[PropertyOrder(4)]
[DisplayName("Dynamic property visible")]
public bool DynamicPropertyIsVisible {
get {
return dynamicPropertyIsVisible;
}
set {
dynamicPropertyIsVisible = value;
}
}
[PropertyOrder(5)]
[DisplayName("Dynamic property readonly")]
public bool DynamicPropertyIsReadOnly {
get {
return dynamicPropertyIsReadOnly;
}
set {
dynamicPropertyIsReadOnly = value;
}
}
// DisplayName and Description are gotten from resource file
// SomeOtherResources.resources
[PropertyOrder(6)]
[GlobalizedProperty(
BaseName = "SomeOtherResources",
DisplayNameId = "Dummy.DisplayName",
DescriptionId = "Dummy.Description"
)]
public string PropertyWithResourcesElseWhere {
get {
return propertyWithResourcesElseWhere;
}
}
// Property with sub properties for testing
// tabbing accross expanded/non expanded items.
[PropertyOrder(7)]
public SomeClassWithProperties Child {
get {
if (child == null) {
child = new SomeClassWithProperties();
}
return child;
}
}
}
}
Static usageProperty behaviour is defined using the attributes Usage without resources is simple, users can use the Using resource files enables globalization, but is slightly more complicated. By default, resources are gotten from a file namespace.class.resources. This can, if needed, be controlled with the Dynamic usageIt is possible to define a Tabbing through propertiesTo make use of the Tab key feature and globalized tool tips for the tool bar buttons, use Points of interestIf no resource file is there for the neutral culture, globalization is disabled. But still, One could set up the resources to, e.g., use only one resource file. There is no protection from name clashes then though. The namespace could be prepended to the resource names, but then the names would get very long. For adding languages for the tool tips, compile satellite assemblies containing the PropertyGridUtils.CustomPropertyGrid.<language>.resources file (don't forget signing and giving it the correct assembly version, see PropertyGridUtils\compileResources.bat). The assembly must be located in a <language> subdir, like the nl example. New status bar class (.NET 1.1 only)I also wrote a small status bar class because the standard .NET 1.1 status bar doesn't allow embedding of controls (the .NET 2.0 History
|
||||||||||||||||||||||