Skip to main content

Microsoft Silverlight

Answered Question Can't find static resourceRSS Feed

(0)

davidpni
davidpni

Member

Member

66 points

82 Posts

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?

jasonxz
jasonxz

Participant

Participant

1748 points

527 Posts

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.

davidpni
davidpni

Member

Member

66 points

82 Posts

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]

jasonxz
jasonxz

Participant

Participant

1748 points

527 Posts

Answered Question

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? 

davidpni
davidpni

Member

Member

66 points

82 Posts

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
davidpni

Member

Member

66 points

82 Posts

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)

jasonxz
jasonxz

Participant

Participant

1748 points

527 Posts

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!

andrevieiradematos
andrevie...

Member

Member

6 points

3 Posts

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

royhiggs
royhiggs

Member

Member

2 points

12 Posts

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.

ewart
ewart

Member

Member

10 points

9 Posts

Re: Re: Can't find static resource

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
bradhi

Member

Member

2 points

1 Posts

Re: Re: Can't find static resource

 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

Brad Himelstein
agcalc.com
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities