我正在使用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