Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Can't find static resource
10 replies. Latest Post by bradhi on August 6, 2009.
(0)
davidpni
Member
66 points
82 Posts
06-18-2008 4:54 PM |
So, here is the situation: I have a solution with two projects in it. My main project which contains App.xaml has a style meant for buttons. It looks something like this:
<Style x:Key="GlassButtonLeftFlat" TargetType="Button"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="Button" x:Key="GlassButton"> ...more xaml.... </ControlTemplate> </Setter.Value> </Setter></Style>
In my other project which is a Silverlight Class Library included in my solution needs to use that style for its buttons. So in one of my XAML files I have something like this:
<Button Style="{StaticResource GlassButtonLeftFlat}"></Button>
Unfortunately it gives me an error:
Error 1 Cannot find a Resource with that Name/Key [Line: 41 Position: 65]
Does anyone know how I can properly reference that style contained in my App.xaml?
jasonxz
Participant
1748 points
527 Posts
06-18-2008 5:47 PM |
I'm going to assume that your Application references your control library. If that's the case, you can't access the App.xaml that's in the Application from your library.
Your 2 options, as far as I know, are:
06-18-2008 5:55 PM |
Now in order to put the style definition in the library would I just create a XAML file and inside the XAML file make a ResourceDictionary? and then save it and call it something like "generic.xaml"?
[edit]
Just to make things clear...I actually just tried to do that (what I asked about directly above), and it didn't work. I get the same error.
[/edit]
06-18-2008 6:05 PM |
I've noticed VS has a problem with finding Style definitions in both generic.xaml and App.xaml. It doesn't seem to be a consistent problem, though. I've received the same error sporadically when the Style is in App.xaml (I haven't tried putting a Style in generic.xaml, yet -- soon). But, the app runs just fine, if the Style is properly defined, even though VS shows an error.
So, does the app run?
06-18-2008 6:07 PM |
It runs...I just haven't tried using the control I have been making in anything yet since VS has been giving me errors :-)
06-18-2008 6:14 PM |
Okay I tried placing the control on my canvas and it does indeed run fine (with my style applied to it)....Visual Studio just likes to give me errors about it. So it runs fine...but I can't see it in the XAML preview thingy. Oh well. That's cool. Thanks. (and I don't need the generic.xaml either...I can reference it directly from App.xaml)
06-18-2008 6:38 PM |
davidpni:and I don't need the generic.xaml either...I can reference it directly from App.xaml
Cool! That's good to know!
andrevie...
6 points
3 Posts
06-20-2008 8:04 AM |
jasonxz: davidpni:and I don't need the generic.xaml either...I can reference it directly from App.xaml Cool! That's good to know!
i have the same problem here: style defined in App.xaml gives me "Cannot find a Resource with that Name/Key [Line: 35 Position: 205]" exception when i try to run the application
i'm using silverlight 2 beta2 and blend 2.5 june preview
when i create the style, i chose "create in application"
i can see the style defined in the resource panel, under App.xaml
i can also use it in blend (the drag and drop thing) and it wors perfectly
my problem is that VS2008 gives me errors but the application doesn't work
any ideas?
thanks
royhiggs
2 points
12 Posts
09-28-2008 12:06 AM |
First, am I the only one that thinks it is wierd that a control library can use an app.xaml file declared in an application project? The control library should be able to exist without any knowledge of the application, right? Seems like a circular dependency issue and that it shouldn't be allowed.
Second, I'm having the same issue. I put my styles in a generic.xaml file in my control library. I had to go into visual studio from Blend in order to set the file as a resourc file and remove the Custom Tool setting. I then had to close Blend and reopen it because it didn't pick up the change. After that, Blend saw generic.xaml as a resource file and shows my styles in the resource tab. However, when I drop the style onto a button (for a button style) it sets the Style property correctly but gives me the error that it can't find the resource. It's killing me. If I drag and drop it, it should be able to find it.
ewart
10 points
9 Posts
05-30-2009 2:42 AM |
Did anyone ever find a solution to this? e.g. VS2008 will not show a preview but it will run just fine in the browser?
I want to be able to define several themes and swtich between them and so I moved my <Style><Setter> xaml to a custom control and out of the .app file but I still get a problem previewing my custom control... so frustrating. using the production version/release of silverlight 2.0
regards
ewart.
www.onesportevent.com
bradhi
1 Posts
08-06-2009 8:57 AM |
I'm working in a solution now that has several projects in it, some of them can see resources in app.xaml others can't and I cant find anything different about those that cant see it. Does anyone know if this is fixed in Silverlight 3?
thanks,
Brad
agcalc.com