我的app.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>
Run Code Online (Sandbox Code Playgroud)
我在这里尝试使用它:
private void btnOK_Click(object sender, RoutedEventArgs e)
{
RadialGradientBrush b = (RadialGradientBrush)Resources["myBrush"];
//b.GradientStops[1] = new GradientStop(Colors.Red,0.0);
}
Run Code Online (Sandbox Code Playgroud)
但我不能使用"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");
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助
归档时间: |
|
查看次数: |
1815 次 |
最近记录: |