wpf窗口启动图像

发布于 2024-10-18 03:24:37 字数 681 浏览 11 评论 0原文

理想情况下,我希望将窗口的资源保留在资源字典中,但在声明 window.resources 部分之前,我一直在寻找让它们知道的最佳方法。所以我最终做了类似下面代码的事情。

有没有办法静态引用背景图像画笔?我怎样才能做得更好?

干杯,
贝里尔

<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>

I would ideally like to keep the resources for a window in a resource dictionary, but am getting stuck as to the best way to make them known before you declare the window.resources section. So I wind up doing something like the code below.

Is there someway to reference the background image brush statically? How can I do better?

Cheers,
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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别在捏我脸啦 2024-10-25 03:24:37

在您的项目中的 Application.xaml 文件中 Application .资源部分。

您还可以使用独立的资源文件并将其包含在 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>

In your projects Application.xaml file in the Application.Resources Section.

Your could also use a standalone Resource File and include it in your windows xaml file or the Application.xaml file.

<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>

Or

<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>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文