gpt4 book ai didi

wpf - 无法访问 app.xaml 中定义的资源

转载 作者:行者123 更新时间:2023-12-04 01:25:32 42 4
gpt4 key购买 nike

我正在使用 Visual Studio 2010 RC1。

我在 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 中定义的资源?

最佳答案

如果您已将 Startup Object 设置为自定义类,则需要创建自定义 Application 类并调用其 InitializeComponent 方法,如下所示:

App app = new App();
app.InitializeComponent();

更新:正如@qqww2 建议的 InitializeComponent通话可以移到 App里面类构造函数。

关于wpf - 无法访问 app.xaml 中定义的资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2487336/

42 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com