Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - custom control in dll

 
 
Old 03-28-2006   #1 (permalink)
domi


 
 

custom control in dll

Hi,

I built a couple of custom controls (derived from ItemsControl) in a DLL and
I created a "StyleDictionary.xaml" file where I define a resourcedictionary
with the style and control template to apply on these custom controls.
However, I cannot get these styles to be applied on the controls in the main
application. If I copy by hand the styles in the app.xaml, everything works
fine. So it seems the resources I define in the DLL do not get imported. (I
checked Application.Current.Resources.Keys and I do not see my styles)
How should I do that?

Thanks,

Dominique

My System SpecsSystem Spec
Old 03-29-2006   #2 (permalink)
Marcus


 
 

Re: custom control in dll

While I did not try explicitelly the same thing as you did... I saw
some code that does a pretty similar job... So the best I can do is
point you in a direction I figure is good...

The "Source" property of the ResourceDictionary can be used to specify
where to take the content of the ResourceDictionary...

I have had many problems trying to just build a dictionary from a XAML
file (see example below)

<Window ... >
<Window.ResourceDictionary Source="my_uri" />
</Window>

But instead... a friend of mine was able to do soemthing like this...

<Window ...>
<Window.ResourceDictionary>

<MergedDictionaries>
<ResourceDictionary Source="my_uri" />
</MergedDictionaries>

<!-- Other resources -->
...

</Window.ResourceDictionary>
</Window>

For the Source uri, I suggest you consult the documentation on the
ThemeDictionary as it provides some example on how to access resources
from within an assembly...

Please just remember that I did not do this myself and that some more
research is gonna be needed from your side... Although I would be
interested in knowing the result...

Hope this could help...

Marcus

My System SpecsSystem Spec
Old 03-29-2006   #3 (permalink)
Erik Thomas


 
 

RE: custom control in dll

Ernie Booth does a good job of explaining this in one of his blog posts:

http://blogs.msdn.com/ebooth/archive...03/508642.aspx

Erik

"domi" wrote:

> Hi,
>
> I built a couple of custom controls (derived from ItemsControl) in a DLL and
> I created a "StyleDictionary.xaml" file where I define a resourcedictionary
> with the style and control template to apply on these custom controls.
> However, I cannot get these styles to be applied on the controls in the main
> application. If I copy by hand the styles in the app.xaml, everything works
> fine. So it seems the resources I define in the DLL do not get imported. (I
> checked Application.Current.Resources.Keys and I do not see my styles)
> How should I do that?
>
> Thanks,
>
> Dominique

My System SpecsSystem Spec
Old 03-30-2006   #4 (permalink)
Marcus


 
 

Re: custom control in dll

The only thing missing from that post is the URI for loading resources
from another assembly...

I re-checked the ThemeDictionary documentation I refered to in my first
reply and did not find the information I tought would be there...

I rechecked were I saw that information and finally it was from a
sample from Chaz`s blog:

http://blog.rioterdecker.net/blogs/chaz/

The URI he uses to load a resource dictionary from another assembly is
the following:

"RD.RoutedTheme.Sample.Luna;;;component\themes/Resource_LunaNormal.baml"

formatted as follows:

AssemblyName;vVersion;PublicKeyToken;component\resource_name

My System SpecsSystem Spec
Old 03-30-2006   #5 (permalink)
Erik Thomas


 
 

Re: custom control in dll

Thanks, Marcus, that's a great post. I've added chaz to my feed aggregator.

"Marcus" wrote:

> The only thing missing from that post is the URI for loading resources
> from another assembly...
>
> I re-checked the ThemeDictionary documentation I refered to in my first
> reply and did not find the information I tought would be there...
>
> I rechecked were I saw that information and finally it was from a
> sample from Chaz`s blog:
>
> http://blog.rioterdecker.net/blogs/chaz/
>
> The URI he uses to load a resource dictionary from another assembly is
> the following:
>
> "RD.RoutedTheme.Sample.Luna;;;component\themes/Resource_LunaNormal.baml"
>
> formatted as follows:
>
> AssemblyName;vVersion;PublicKeyToken;component\resource_name
>
>

My System SpecsSystem Spec
Old 03-30-2006   #6 (permalink)
domi


 
 

Re: custom control in dll

Thanks for the links.

I found that my style xaml file needed to be named "generic.xaml" But I have
no idea why, and if it can be changed?

"Erik Thomas" wrote:

> Thanks, Marcus, that's a great post. I've added chaz to my feed aggregator.
>
> "Marcus" wrote:
>
> > The only thing missing from that post is the URI for loading resources
> > from another assembly...
> >
> > I re-checked the ThemeDictionary documentation I refered to in my first
> > reply and did not find the information I tought would be there...
> >
> > I rechecked were I saw that information and finally it was from a
> > sample from Chaz`s blog:
> >
> > http://blog.rioterdecker.net/blogs/chaz/
> >
> > The URI he uses to load a resource dictionary from another assembly is
> > the following:
> >
> > "RD.RoutedTheme.Sample.Luna;;;component\themes/Resource_LunaNormal.baml"
> >
> > formatted as follows:
> >
> > AssemblyName;vVersion;PublicKeyToken;component\resource_name
> >
> >

My System SpecsSystem Spec
Old 03-31-2006   #7 (permalink)
Marcus


 
 

Re: custom control in dll

themes/generic.xaml is the default lookup name if no Theme specific
resource is present...

In your custom control, you should see in the static constructor that a
line is present to specify that the default control's style should be
overriden by what is present in the generic.xaml.

While I did not try do much testing with this "line", I believe that
removing that line will cause your control to use it`s base class style
and template instead of the one you provide in your generic.xaml.

About changing the name of the generic.xaml... If you can`t find a way
to do this, let me know... I wasn't able (only looked quickly, I think
this is one of the hard-coded things from the framework) you can always
use the methods stated previously in this thread to load the resources
from other dictionaries...

I also suggest looking at the ThemeInfoAttribute located in the
AssemblyInfo.cs, that allows you to specify where to look for your
resources (for the generic and themes resources)... While this does not
allow you to change the name if the xaml file, it allows you to specify
other assemblies...

My System SpecsSystem Spec
Old 03-31-2006   #8 (permalink)
Marcus


 
 

Re: custom control in dll

I just had a flash about what you said...

The documentation mentions that the generic resource dictionary will be
looked-up if the "page" dictionary containing the control does not have
the required resource or if there is not theme specific dictionary...

What that means is that you should be able to place your style and
template in a separate XAML... merge that dictionary to the "page"
dictionary and then apply a style and template from that dictionary to
your control...

What generic.xaml brings to you is the ability to provide a default
style and template.

Even further... always according to the documentation. That would mean
that you could provide only "bases" for your style and template in your
separate XAML and put in the generic/theme specific dictionaries the
components of your control that you wish changes from theme to theme...
You would then have a "basic" layout for your control but an adaptative
look...

Once again, since I am a little busy at the moment (or lazy, take your
pick) I did not test that, so you would have to test it by yourself...
Next time, I'm gonna try to provide more samples/real life
situations...

Hope this bit of information can help

Marcus


Marcus wrote:
> themes/generic.xaml is the default lookup name if no Theme specific
> resource is present...
>
> In your custom control, you should see in the static constructor that a
> line is present to specify that the default control's style should be
> overriden by what is present in the generic.xaml.
>
> While I did not try do much testing with this "line", I believe that
> removing that line will cause your control to use it`s base class style
> and template instead of the one you provide in your generic.xaml.
>
> About changing the name of the generic.xaml... If you can`t find a way
> to do this, let me know... I wasn't able (only looked quickly, I think
> this is one of the hard-coded things from the framework) you can always
> use the methods stated previously in this thread to load the resources
> from other dictionaries...
>
> I also suggest looking at the ThemeInfoAttribute located in the
> AssemblyInfo.cs, that allows you to specify where to look for your
> resources (for the generic and themes resources)... While this does not
> allow you to change the name if the xaml file, it allows you to specify
> other assemblies...


My System SpecsSystem Spec
 

Thread Tools



Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46