我正在使用Visual Studio 2010 RC1。无法访问app.xaml中定义的资源
我app.xaml_定义资源“Brush2”:
<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>
在我的主窗口,我尝试使用资源:
...
<Border Margin="4,2" BorderBrush="Black" BorderThickness="2" CornerRadius="4"
ToolTip="{Binding Path=FullPath}" HorizontalAlignment="Stretch"
Background="{StaticResource Brush2}">
...
不管我做什么,它总是引发运行时异常(未找到资源)。我改变了 构建行动没有成功。
如何使用app.xaml中定义的资源?
感谢您的建议,它终于有效。我明确地将项目属性中的启动对象设置为我自己定义的某个类。我将其改为“(未设置)”,它起作用。多么奇怪...... – DerKlaus 2010-03-21 15:33:56
这实际上是有道理的。未设置将导致App.xaml被解释为找出在启动时要做什么。将它设置为你自己的类将导致这种情况不会发生,除非你明确做到了。 – 2010-03-21 15:39:46
@DerKlaus - 感谢您的评论!我将App.xaml的构建操作设置为Page,这样我就可以创建自己的入口点。 (这当然会导致我在设计时从加载样式中丢失我的共享资源字典)。我不知道在读取评论之前,我可以在项目属性中设置启动对象。这使我可以将App.xaml的构建操作设置回应用程序定义!再次感谢! – Scott 2010-05-27 20:21:07