gpt4 book ai didi

c# - 无法从应用程序级别获取资源

转载 作者:太空狗 更新时间:2023-10-30 00:43:37 27 4
gpt4 key购买 nike

我的应用程序.xaml:

<Application.Resources>
<RadialGradientBrush x:Key="myBrush">
<GradientStop Color="#FFC44EC4" Offset="0" />
<GradientStop Color="#FF829CEB" Offset="1" />
<GradientStop Color="#FF793879" Offset="0.669" />
</RadialGradientBrush>
</Application.Resources>

我在这里尝试使用它:

private void btnOK_Click(object sender, RoutedEventArgs e)
{
RadialGradientBrush b = (RadialGradientBrush)Resources["myBrush"];
//b.GradientStops[1] = new GradientStop(Colors.Red,0.0);
}

但我不能使用“b”,因为它在定义后为空。我怎样才能获得该资源?

最佳答案

您正在从控件的资源中“绘制”,请尝试使用其中一种...

res = this.FindResource("myBrush"); // this 'walks' the tree and will find it
res = Application.Current.Resources["myBrush"]; // or reference app resources directly
res = App.Current.TryFindResource("myBrush");

希望对你有帮助

关于c# - 无法从应用程序级别获取资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10402256/

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