1. Add a new class to the shell application
2. Add references and using statements for the following libraries
Microsoft.Practices.CompositeUI3. Inherit the class from
Microsoft.Practices.CompositeUI.WinForms
System.Windows.Forms
a. IUIElementAdapter - for specialized implementation4. Implement the members of the interface as follows
OR
b. UIElementAdapter - for basic common behavior
a. Add - this method should add an element to the controlIf you want to be able to register extension sites using an instance of the control, you must also create factory for the types of control your adapter handles.
b. Remove - this method should remove an item from the specified control
Create a UIElement adapter factory
1. Add a new class to the shell application
2. Specify that the class will implement the IUIElementAdpaterFactory interface from the
Microsoft.Practices.CompositeUI.UIElements namespace3. Implement the IUIElementAdapterFactory interface. You must provide the Supports method that determines whether the object passed to the method is of the right type. For example, if your adapter is designed to work with the Windows Forms TreeNode class, the code you require is:
public class MyAdapterFactory : IUIElementAdapterFactory
{
...
}
public bool Supports(object myElement)4. You must also implement the GetAdapter method to return an instance of your custom adapter that is suitable for the object type:
{
return (myElement is TreeNode);
}
public IUIElementAdapter GetAdapter(object myElement)Once you have created the custom adapter factory, you must register it with the adapter factory catalog.
{
return new MyTreeNodeAdapter(...);
}
Register a UIElement adapter factory in the adapter factory catalog:
Override the AfterShellCreated method in your application class to get a reference to the IUIElementAdpterFactoryCatalog from the Services collection of the RootWorkItem and call the RegisterFactory method:
public class MyApplication : FormShellApplication<..., ...>
{
...
protected override void AfterShellCreated()
{
base.AfterShellCreated();
IUIElementAdpterFactoryCatalog catalog;
catalog = RootWorkItem.Services.Get();
catalog.RegisterFactory(new MyAdapterFactory());
}
...
}
No comments:
Post a Comment