Page view counter
Can't find static resource
Last post 09-28-2008 12:06 AM by royhiggs. 8 replies.
Sort Posts:
06-18-2008 4:54 PM
Can't find static resource

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?

davidpni

Loading...
Joined on 05-16-2008
Posts 82
06-18-2008 5:47 PM
Re: Can't find static resource

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:

  1. Set the Style property of your Button in the Application.
  2. Put the Style definition in your library.
jasonxz

Loading...
Joined on 04-17-2007
Arlington, TX
Posts 522
06-18-2008 5:55 PM
Re: Can't find static resource

 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]

davidpni

Loading...
Joined on 05-16-2008
Posts 82
06-18-2008 6:05 PM
Marked as Answer
Re: Can't find static resource

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? 

jasonxz

Loading...
Joined on 04-17-2007
Arlington, TX
Posts 522
06-18-2008 6:07 PM
Re: Can't find static resource

 It runs...I just haven't tried using the control I have been making in anything yet since VS has been giving me errors :-)

davidpni

Loading...
Joined on 05-16-2008
Posts 82
06-18-2008 6:14 PM
Re: Can't find static resource

 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)

davidpni

Loading...
Joined on 05-16-2008
Posts 82
06-18-2008 6:38 PM
Re: Can't find static resource

davidpni:
and I don't need the generic.xaml either...I can reference it directly from App.xaml

Cool!  That's good to know!

jasonxz

Loading...
Joined on 04-17-2007
Arlington, TX
Posts 522
06-20-2008 8:04 AM
Re: Can't find static resource
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

andrevieiradematos

Loading...
Joined on 06-20-2008
Posts 3
09-28-2008 12:06 AM
Re: Can't find static resource

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.

royhiggs

Loading...
Joined on 12-07-2006
Posts 12
Microsoft Communities