Porting WPF app to class library -> How to handle themes, resources and
paths?
I am working on making class libraries for use in another application. My
class library is in a separate folder than the application itself and is
loaded and run by the application. I am running into many problems porting
the code. Anywhere a resource, theme or code that resolves references is
used exceptions are thrown like crazy.
For example, in the application there will be code like this:
var directoryCatalog = new DirectoryCatalog(@"./");
Needs to be modified to the following in order to correctly discover
assemblies that are in the class libraries folder:
var directoryCatalog = new
DirectoryCatalog(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));
My question is how to handle custom controls and themes. I have a
theme.xaml file and it is loaded with the following code:
CurrentTheme = new ResourceDictionary
{
Source = new
Uri("/Gemini;component/Themes/VS2010/Theme.xaml",
UriKind.Relative)
};
However this is never found, and never loaded since it is relative and the
running applications directory does not contain this resource. How would
you modify the Uri code so it will find the resource in the current
executing assemblies directory?
If I manually create a Uri hard coded to the class libraries folder then
it will load the first few lines, but then when it hits a style for a
custom control it states:
'Failed to create a 'Type' from the text 'toolbars:ToolBarEx'
My theme file:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mainmenu="clr-namespace:Gemini.Modules.MainMenu.Controls"
xmlns:toolbars="clr-namespace:Gemini.Modules.ToolBars.Controls"
xmlns:xcad="http://schemas.xceed.com/wpf/xaml/avalondock">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Brushes.xaml" />
<ResourceDictionary Source="StatusBar.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style TargetType="{x:Type ContextMenu}">
<!-- BasedOn="{StaticResource {x:Type ContextMenu}} -->
<Setter Property="Background" Value="{StaticResource
ContextMenuBackground}" />
<Setter Property="BorderBrush" Value="{StaticResource
ContextMenuBorderBrush}" />
<Setter Property="BorderThickness" Value="1" />
</Style>
<Style TargetType="{x:Type ToolBar}">
<!-- BasedOn="{StaticResource {x:Type ToolBar}}" -->
<Setter Property="Background" Value="{StaticResource
ToolBarBackground}" />
</Style>
<Style TargetType="{x:Type toolbars:ToolBarEx}">
<!-- BasedOn="{StaticResource {x:Type ToolBar}}" -->
<Setter Property="Background" Value="{StaticResource
ToolBarBackground}" />
</Style>
So it is working up until it gets to the extended ToolBarEx. I read that
this was resolved by others by adding a reference to the class library and
add using statements so these namespaces could be found.
The main application my class library is working with exposes a standard
add-in interface and since it is a commercial project I can't add a
reference or using statements to their code.
How would you get this to work? How do I tell .NET to stop looking in the
application directory and only pay attention to what is going on in the
class library directory?
No comments:
Post a Comment