我在ResourceDictionary
. 我创建了一个窗口来更改 ThemeColor。这种颜色绑定到我的ResourceDictionary
.
这是我的资源字典:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ns="clr-namespace:Phoenix_CRM" >
<LinearGradientBrush x:Key="DegradeCouleurTheme" StartPoint="0,0" EndPoint="0,1" >
<GradientStop Offset="0" Color="{x:Static ns:CParametres.ColorBegin}" />
<GradientStop Offset="1" Color="{x:Static ns:CParametres.ColorEnd}"/>
</LinearGradientBrush>
</ResourceDictionary>
我创建了一个 CParameters 类来设置颜色参数。构成渐变的两种颜色保存在数据库中。此类旨在加载/保存颜色并应用它。
这是我更改颜色的课程:
public class CParametres : INotifyPropertyChanged
{
private Color m_ThemeColorGradientBegin;
public Color ThemeColorGradientBegin
{
get { return m_ThemeColorGradientBegin; }
set
{
m_ThemeColorGradientBegin = value;
ColorBegin = m_ThemeColorGradientBegin;
FirePropertyChangedEvent("ColorBegin");
}
}
private Color m_ThemeColorGradientEnd;
public Color ThemeColorGradientEnd
{
get { return m_ThemeColorGradientEnd; }
set
{
m_ThemeColorGradientEnd = value;
ColorEnd = m_ThemeColorGradientEnd;
FirePropertyChangedEvent("ColorEnd");
}
}
public static Color ColorBegin;
public static Color ColorEnd;
public CParametres()
{
....
....
}
public void LoadGradientDefault()
{
ThemeColorGradientBegin = (Color)ColorConverter.ConvertFromString("#00b6e7");
ThemeColorGradientEnd = (Color)ColorConverter.ConvertFromString("#0086d6");
}
public void LoadParams()
{
if (ReadParamFromDB() == true)
{
setThemeGradient(m_ThemeColorGradientBegin, m_ThemeColorGradientEnd);
}
}
public void setThemeGradient(Color ColorBegin, Color ColorEnd)
{
this.ThemeColorGradientBegin = ColorBegin;
this.ThemeColorGradientEnd = ColorEnd;
}
public event PropertyChangedEventHandler PropertyChanged;
private void FirePropertyChangedEvent(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
当我更改颜色时,我需要退出并重新运行我的应用程序才能看到更改。请问有人知道强制直接应用新颜色吗?
任何人都可以向我解释一下刷新 UI 的提示是什么?