I am using Visual Studio 2010 RC1.
I define a resource “Brush2” in app.xaml_:
<Application x:Class="VideoThumbnails.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<RadialGradientBrush x:Key="Brush2" RadiusX="1" RadiusY="1" GradientOrigin="0.3,0.3">
<GradientStop Color="White" Offset="0"/>
<GradientStop Color="#ffc0c0" Offset="1"/>
</RadialGradientBrush>
</Application.Resources>
</Application>
In my Mainwindow I am trying to use that resource:
...
<Border Margin="4,2" BorderBrush="Black" BorderThickness="2" CornerRadius="4"
ToolTip="{Binding Path=FullPath}" HorizontalAlignment="Stretch"
Background="{StaticResource Brush2}">
...
No matter what I do it always raises an exception at runtime (Resource not found). I changed
build action without success.
How can I use resources defined in app.xaml?
Nothing you have done is incorrect. You either have 1) screwed up the project build somehow while randomly doing things to try to get it to work or 2) something else is going on here and we’ll never know without the exception details.
I would highly suggest you try to repro this in a fresh brand new WPF project. Do the following steps (and ONLY the following steps):
Create a new WPF project, add the exact same brush to app.xaml, then open Window1 and bind the window’s background to the resource. Run the app.
It should work as expected. If not, come back with the exception details. If it does, compare this new project with your current one to see what you are doing differently.