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:
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:
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:
Set the Style property of your Button in the Application.
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.
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.
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)
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
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.
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
davidpni
Member
66 Points
82 Posts
Can't find static resource
Jun 18, 2008 08:54 PM | LINK
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
1787 Points
557 Posts
Re: Can't find static resource
Jun 18, 2008 09:47 PM | LINK
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:
davidpni
Member
66 Points
82 Posts
Re: Can't find static resource
Jun 18, 2008 09:55 PM | LINK
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
Participant
1787 Points
557 Posts
Re: Can't find static resource
Jun 18, 2008 10:05 PM | LINK
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
Member
66 Points
82 Posts
Re: Can't find static resource
Jun 18, 2008 10:07 PM | LINK
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
Member
66 Points
82 Posts
Re: Can't find static resource
Jun 18, 2008 10:14 PM | LINK
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
Participant
1787 Points
557 Posts
Re: Can't find static resource
Jun 18, 2008 10:38 PM | LINK
Cool! That's good to know!
andrevieirad...
Member
6 Points
3 Posts
Re: Can't find static resource
Jun 20, 2008 12:04 PM | LINK
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
Member
3 Points
12 Posts
Re: Can't find static resource
Sep 28, 2008 04:06 AM | LINK
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
Member
23 Points
23 Posts
Re: Re: Can't find static resource
May 30, 2009 06:42 AM | LINK
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