我正在使用WPF编程(C#)。我正试图定义一些改变程序皮肤的东西。
我使用此代码:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" x:Class="RFID.OperationWindow" Title="OperationWindow" Height="768" Width="1366" ResizeMode="CanResize" WindowStyle="None" WindowStartupLocation="CenterScreen" WindowState="Maximized">
<Window.Resources>
<LinearGradientBrush x:Key="AquaGradient" EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#FFF6F6F6" Offset="1"/>
<GradientStop Color="#FFEAE8E8" Offset="1"/>
<GradientStop Color="#FFDCD9D9" Offset="1"/>
<GradientStop Color="#FF46AFBF" Offset="0.5"/>
<GradientStop Color="#FFE0DDDD"/>
<GradientStop Color="#FF4EDAF0" Offset="0.018"/>
<GradientStop Color="#FF75C2BF" Offset="0.964"/>
</LinearGradientBrush>
<LinearGradientBrush x:Key="GreenGradient" EndPoint="0,1" StartPoint="0,0">
<GradientStop Color="#FFF3F3F3" Offset="0"/>
<GradientStop Color="#FFEBEBEB" Offset="0.082"/>
<GradientStop Color="#FFDDDDDD" Offset="0.071"/>
<GradientStop Color="#FF0FFB2F" Offset="1"/>
</LinearGradientBrush>
<Window.Resources>
如何将LinearGradientBrush指定给控件背景? 这样的事情:
我对每个控件背景使用AquaGradient
。如何动态地将GreenGradient
分配给所有背景?
例如这样的事情:
AquaGradient = GreenGradient;
答案 0 :(得分:2)
类似的东西:
imageInsertUser.Background = Application.Current.FindResource("GreenGradient");
但通常你想在xaml
中做<Control Background="{StaticResource GreenGradient}">