This topic is second in a multi-part walkthrough. Refer to Creating and Setting Up a ThemePack Project for information on setting up the Microsoft® Visual Studio® 2008 project. In this topic, you will create the style group's class file.
Note: Each style group's class file is similar in content and layout; therefore, this multi-part walkthrough will discuss DataPresenter's style group.
- In the "MyThemePack" project, right click on the DataPresenter folder under ResourceSets. In the pop-up menu, click Add, then click Class.
- In the Add New Item dialog box, name the class file "DataPresenter_ResourceSets" and click Add.
Note: We recommend that you name the class file using the following convention: "StyleGroupName_ResourceSets"
- Change the name of the class (not the class file) from "DataPresenter_ResourceSets" to "DataPresenter." Place the public (Public in Visual Basic) keyword before the class keyword.
- Change the class' namespace from "MyThemePack.ResourceSets.DataPresenter" to "MyThemePack.ResourceSets.OrangePeel."
- Before you start writing any code, you should place using/Imports directives at the top of your class file so you don't need to always type out a member's fully qualified name.
In Visual Basic:
ImportsSystem.ComponentModelImportsSystem.ReflectionImportsInfragistics.WindowsImportsInfragistics.Windows.ThemesIn C#:
usingSystem.ComponentModel;usingSystem.Reflection;usingInfragistics.Windows;usingInfragistics.Windows.Themes;
- The DataPresenter class derives from DataPresenterResourceSet. The ResourceSet that you derive from depends upon the style group (i.e., if you were creating the ResourceSet for the Editors, you would derive from EditorsResourceSet).
In Visual Basic:
Public ClassDataPresenterInheritsDataPresenterResourceSet(OfDataPresenter.Locator) ...End ClassIn C#:
publicclassDataPresenter : DataPresenterResourceSet<DataPresenter.Locator> { ... } - Create a static variable that is an instance of the DataPresenter class and provide a static method that accesses the static instance. This makes sure that there is only one instance of this style's DataPresenterResourceSet at all times.
In Visual Basic:
...Private Sharedg_InstanceAsDataPresenterPublic Shared ReadOnly PropertyInstance()AsDataPresenterGetIfg_InstanceIs Nothing Theng_Instance =NewDataPresenter()End IfReturng_InstanceEnd GetEnd Property...In C#:
...private staticDataPresenter g_Instance;public staticDataPresenter Instance {get{if(g_Instance ==null) g_Instance =newDataPresenter();returng_Instance; } } ...
- A style group's class file must contain a Locator class. The Locator class derives from ResourceSetLocator and defines key properties such as:
- access to the Assembly containing the resource set
- the Theme or name of the style
- the Grouping, which is specific to the style group
- the ResourcePath to the embedded ResourceDictionary for the style group within the assembly
In Visual Basic:
...Public ClassLocatorInheritsResourceSetLocatorPublic Overrides ReadOnly Property[Assembly]()As[Assembly]GetReturn Me.GetType().AssemblyEnd GetEnd PropertyPublic Overrides ReadOnly PropertyTheme()As StringGetReturn"OrangePeel"End GetEnd PropertyPublic Overrides ReadOnly PropertyGrouping()As StringGetReturnDataPresenterGeneric.Instance.GroupingEnd GetEnd PropertyPublic Overrides ReadOnly PropertyResourcePath()As StringGetReturn"ResourceSets\DataPresenter\DataPresenter.xaml"End GetEnd PropertyEnd Class...In C#:
... [EditorBrowsable(EditorBrowsableState.Never)]public classLocator : ResourceSetLocator {public overrideAssembly Assembly {get{returnthis.GetType().Assembly; } }public override stringTheme {get{return"OrangePeel"; } }public override stringGrouping {get{returnDataPresenterGeneric.Instance.Grouping; } }public override stringResourcePath {get{return@"ResourceSets\DataPresenter\DataPresenter.xaml"; } } } ...
The file the ResourcePath is set to is created in the Creating a Style Group's ResourceDictionary Files.
