I have a WPF windows app and from code in Window.xaml.cs I create an
instance of a class whish is derived from Adorner. In this class I create
shapes and need to apply a style from a resource file named
'Dictionary1.xaml'.
Normally if all this code was just running in Window.xaml.cs I could use
this line:
cornerThumb.Style = (Style)this.FindResource("RoundThumbLineEnd");
and use this reference in the window's xaml:
<Window.Resources>
<ResourceDictionary Source="Dictionary1.xaml" />
</Window.Resources>
but of course, the Adorner class where I'm working has no idea where
Dictionary1.xaml is.
Any tips?
Thanks.
-- mo*******@noemail.noemail 2 1712
Hi moondaddy,
When finding a resource, it first checks the current element's Resources
collection (its resource dictionary). If the item is not found, it checks
the parent element, its parent, and so on until it reaches the root
element. At that point, it checks the Resources collection on the
Application object. If it is not found there, it finally checks a system
collection (which contains system-defined fonts, colors, and other
settings). If the item is in none of these collections, it throws an
InvalidOperationException.
Therefore you could simply put resources in App.xaml within
<Application.Resourcesand those resources will be shared by all your code
in the same assembly.
For ResourceDictionary defined in separate .xaml files, you could use
following code to load it:
ResourceDictionary rd = new ResourceDictionary();
rd.Source = new Uri(@"Dictionary1.xaml", UriKind.Relative);
Then you can use rd["resource_key"] to reference each resource.
Hope this helps.
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Great Thanks Walter! This is what I was looking for.
"Walter Wang [MSFT]" <wa****@online.microsoft.comwrote in message
news:Ow**************@TK2MSFTNGHUB02.phx.gbl...
Hi moondaddy,
When finding a resource, it first checks the current element's Resources
collection (its resource dictionary). If the item is not found, it checks
the parent element, its parent, and so on until it reaches the root
element. At that point, it checks the Resources collection on the
Application object. If it is not found there, it finally checks a system
collection (which contains system-defined fonts, colors, and other
settings). If the item is in none of these collections, it throws an
InvalidOperationException.
Therefore you could simply put resources in App.xaml within
<Application.Resourcesand those resources will be shared by all your
code
in the same assembly.
For ResourceDictionary defined in separate .xaml files, you could use
following code to load it:
ResourceDictionary rd = new ResourceDictionary();
rd.Source = new Uri(@"Dictionary1.xaml", UriKind.Relative);
Then you can use rd["resource_key"] to reference each resource.
Hope this helps.
Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: mdh |
last post by:
I am trying to learn the basics of MVC applications using a Tomcat
infrastructure. I'm starting by building a simple application with:
* a login.jsp page for a basic login form with a action...
|
by: Edward Diener |
last post by:
I have a class Y in assembly B which is derived from a class Z in assembly
C. So I correctly add a reference to assembly C in assembly B, build
assembly B and everything builds fine. Now I create...
|
by: Adam |
last post by:
We have a web site that uses .vb for the web pages and .cs for a class
module. We are getting the error in .NET 2.0 and VS 2005 beta 2. It does
work with .NET 1.1.
When trying to access a page...
|
by: Mike Logan |
last post by:
I used WSDL.exe to generate a client side web proxy for a web service, called
the web service, got the results but an array returned by the web service is
not in the results.
However if I use...
|
by: Richard Lewis Haggard |
last post by:
We are having a lot of trouble with problems relating to failures relating
to 'The located assembly's manifest definition with name 'xxx' does not
match the assembly reference" but none of us here...
|
by: raylopez99 |
last post by:
I'm having problems compiling complex reference declarations in
MSVC++.NET 2002 IDE.
Here is an example:
// --Foo.h--
#include "Bar.h"
class Bar; //forward decl. to a class Bar in...
|
by: ken |
last post by:
Hi,
i have a class:
class LogHandler(ContentHandler):
# a reference to a file open by some other function/class
outputFile;
def endElement(self, name):
doSomething(self,...
|
by: Davidhere40 |
last post by:
Do I have to use a web reference to access use a remote web reference?
I can't seem to just use the proxy generated by my web services
project, because that one never calls the remote service, its...
|
by: balabaster |
last post by:
Hi all,
I'm creating a class factory and a bunch of adapters to allow in house applications to communicate with mobile applications over different cellular networks.
I've got my class...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |