作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero">
<LinearGradientBrush x:Key="ButtonNormalBackgroundBrush"
StartPoint = "0.5,0"
EndPoint = "0.5,1">
<GradientStop Color="#C10099FF" Offset="0"/>
<GradientStop Color="#C16699CC" Offset="1"/>
<GradientStop Color="#C1006699" Offset="0.49"/>
</LinearGradientBrush>
<ResourceDictionary/>
现在我想从 ResourceDictonary 获取 LinearGradientBrush 并将其作为 wpf 中的背景色动态应用到按钮。
BtnGetBrushes.Background = Brushes.Green;
我想应用上面的颜色而不是这个(Brushes.Green)。我应该怎么做?
最佳答案
假设您的 ResourceDictionary 在上下文中可用:
<Button Background="{DynamicResource ResourceKey=ButtonNormalBackgroundBrush}" />
或在代码中
button.Background = (Brush)FindResource("ButtonNormalBackgroundBrush");
关于c# - 如何从 XAML 中定义的 ResourceDictionary 检索 Brush 并将其应用于代码中的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12152803/
我是一名优秀的程序员,十分优秀!