理想情况下,我希望保留资源字典中窗口的资源,但在声明window.resources部分之前,最好的方法是让它们知道。所以我最终做了类似下面代码的事情。
有什么方法可以静态引用背景图像画笔吗?我怎么能做得更好?
干杯,
Berryl
<Window x:Class="Smack.ConstructionAdmin.Presentation.Wpf.Views.ProjectPicker.ProjectPickerView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
...
Background="{DynamicResource waveBrush}"
Icon="pack://application:,,,/MyAssembly;component/Images/Project_32.png"
...
>
<Window.Resources>
<ImageBrush
x:Key="waveBrush" Stretch="Fill" ImageSource="pack://application:,,,/MyAssembly;component\Images\Wave.jpg"
/>
</Window.Resources>
答案 0 :(得分:1)
在Application.Resources
部分的项目Application.xaml文件中。
您也可以使用独立的资源文件,并将其包含在Windows xaml文件或Application.xaml文件中。
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" Background="{DynamicResource MyBackColor}">
<Window.Resources>
<ResourceDictionary Source="Resources\MyResourceDictionary.xaml" />
</Window.Resources>
<Grid>
</Grid>
</Window>
或者
<Application x:Class="WpfApplication1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary Source="Resources\MyResourceDictionary.xaml" />
</Application.Resources>