Images not loading in windowbase from external DLL
-
16 aprilie 2012 12:43
Hey there,
I've got a question regarding loading in images from a dll in a custom made window.
I started out making a WPF Content Control Library project (MyRes), where I made my own windowclass (MyWindow), to which I apply a style.
public class MyWindow : Window { public MyWindow() { this.Loaded += WindowLoaded; DefaultStyleKeyProperty.OverrideMetadata(typeof(MyWindow), new FrameworkPropertyMetadata(typeof(MyWindow))); } }
The general layout of the Themes\Generic.xaml is as following:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:MyRes"> <BitmapImage x:Key="leftImage" UriSource="/MyRes;component/Resources/Images/img1.bmp" /> <BitmapImage x:Key="bgImage" UriSource="/MyRes;component/Resources/Images/img2.tiff" /> <BitmapImage x:Key="rightImage" UriSource="/MyRes;component/Resources/Images/img3.jpg" /> <Style TargetType="{x:Type local:MyWindow"}> ... //Bunch of setters <!-- Set the template --> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type local:MyWindow}"> <Grid> <Grid.Background> <ImageBrush ImageSource="{StaticResource bgImage}"/> </Grid.Background> ... //row and col defs <Image Grid.Column="0" Grid.Row="0" Source="{StaticResource leftImage}" ..other properties. />
... //more images and buttons and statusbars etc
<AdornerDecorator>
<ContentPresenter Content="{TemplateBinding Content}" Grid.Column="1" Grid.Row="1" Grid.ColumnSpan="3" Margin="{TemplateBinding Margin}" />
</AdornerDecorator>If I initialise this window in a new project, after referencing the DLL that comes out, like this:
<bwr:MyWindow x:Class="TestProject.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:bwr="clr-namespace:MyRes;assembly=MyRes" Title="MainWindow"> <Grid> </Grid> </bwr:MyWindow>All the properties and layouts are applied to the window, but both of the images are not loaded correctly.
I tried both relative and absolute URI's, setting the image as 'content', 'resource' and 'embedded resource', but I can't find out why it won't load correctly.
Any help would be greatly appreciated.
Thanks in advance,
Shane
- Editat de Shane_C 16 aprilie 2012 12:44
Toate mesajele
-
18 aprilie 2012 07:05Moderator
Hi Shane,
Please refer to the WPF Pack Uri in this link: http://msdn.microsoft.com/en-us/library/aa970069.aspx
Try "pack://application:,,,/ReferencedAssembly;component/Subfolder/ResourceFile.xaml" absolute pack Uri in the referenced assembly.
Have a nice day,
Kee Poppy [MSFT]
MSDN Community Support | Feedback to us
- Marcat ca răspuns de Kee PoppyModerator 30 aprilie 2012 04:09