对于我的Windows手机应用程序,我创建了两个主题Dark
和Light
,当我从Light
选择listpicker
时,我的Light
主题如下:
但是我从Dark
中选择了listpicker
,主题背景并没有变化,只有前景发生变化,即下面:
以下是listpicker
selectionchange方法:
private void themelistPicker1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (themelistPicker1 != null && themelistPicker1.SelectedIndex > -1)
{
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
ListPickerItem lpi = (sender as ListPicker).SelectedItem as ListPickerItem;
string themename = lpi.Content.ToString();
if (!settings.Contains("userData"))
settings.Add("userData", themename);
else
settings["userData"] = themename;
settings.Save();
try
{
if (themename == "Dark")
{
themelistPicker1.SelectedIndex = 0;
tblk_settings.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 80, 239));
tblk_theme.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 80, 239));
tblk_text.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 80, 239));
tblk_bg.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 80, 239));
themelistPicker1.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 80, 239));
themelistPicker1.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 0, 80, 239));
LayoutRoot.Background = linear;
//App.RootFrame.Background = linear;
ApplicationBar.BackgroundColor = Colors.Blue;
}
else
{
themelistPicker1.SelectedIndex = 1;
tblk_settings.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
tblk_theme.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
tblk_text.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
tblk_bg.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
themelistPicker1.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
themelistPicker1.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
LayoutRoot.Background = myLinearGradientBrush;
//App.RootFrame.Background = myLinearGradientBrush;
ApplicationBar.BackgroundColor = Color.FromArgb(255, 0, 138, 0);
}
}
catch { }
}
}
下面的是theme
页面的构造函数:
public themes()
{
InitializeComponent();
try
{
LinearGradientBrush linear = new LinearGradientBrush();
linear.StartPoint = new Point(0, 0);
linear.EndPoint = new Point(1, 1);
linear.GradientStops.Add(new GradientStop() { Color = Colors.Blue, Offset = 0.0 });
linear.GradientStops.Add(new GradientStop() { Color = Colors.Cyan, Offset = 0.25 });
linear.GradientStops.Add(new GradientStop() { Color = Colors.Blue, Offset = 0.75 });
linear.GradientStops.Add(new GradientStop() { Color = Colors.Purple, Offset = 0.1 });
LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush();
myLinearGradientBrush.StartPoint = new Point(0.5, 0.0);
myLinearGradientBrush.EndPoint = new Point(0.5, 1.0);
myLinearGradientBrush.GradientStops.Add(new GradientStop() { Color = Color.FromArgb(225, 164, 196, 0), Offset = 0.0 });
myLinearGradientBrush.GradientStops.Add(new GradientStop() { Color = Color.FromArgb(255, 96, 169, 23), Offset = 0.567 });
myLinearGradientBrush.GradientStops.Add(new GradientStop() { Color = Color.FromArgb(255, 0, 138, 0), Offset = 1.0 });
myLinearGradientBrush.Opacity = 50;
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
if (settings.Contains("userData"))
{
localsettings = IsolatedStorageSettings.ApplicationSettings["userData"] as string;
}
else
{
settings["userData"] = "Dark";
localsettings = "Dark";
}
settings.Save();
if (localsettings == "Dark")
{
tblk_settings.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 80, 239));
tblk_theme.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 80, 239));
tblk_text.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 80, 239));
tblk_bg.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 80, 239));
themelistPicker1.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 80, 239));
themelistPicker1.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 0, 80, 239));
LayoutRoot.Background = linear;
//App.RootFrame.Background = linear;
ApplicationBar.BackgroundColor = Colors.Blue;
}
else if (localsettings == "Light")
{
tblk_settings.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
tblk_theme.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
tblk_text.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
tblk_bg.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
themelistPicker1.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
themelistPicker1.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
LayoutRoot.Background = myLinearGradientBrush;
//App.RootFrame.Background = myLinearGradientBrush;
ApplicationBar.BackgroundColor = Color.FromArgb(255, 0, 138, 0);
}
}
catch
{
}
}
我为Dark
主题定义了两个Gredients'linear',为myLinearGradientBrush
主题定义了Light
以下是OnNavigatedTo
方法:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
try
{
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
if (settings.Contains("userData"))
{
string str = settings["userData"].ToString();
if (str == "Dark")
{
themelistPicker1.SelectedIndex = 0;
tblk_settings.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 80, 239));
tblk_theme.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 80, 239));
tblk_text.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 80, 239));
tblk_bg.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 80, 239));
themelistPicker1.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 80, 239));
themelistPicker1.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 0, 80, 239));
LayoutRoot.Background = linear;
//App.RootFrame.Background = linear;
ApplicationBar.BackgroundColor = Colors.Blue;
}
else
{
themelistPicker1.SelectedIndex = 1;
tblk_settings.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
tblk_theme.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
tblk_text.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
tblk_bg.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
themelistPicker1.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
themelistPicker1.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
LayoutRoot.Background = myLinearGradientBrush;
//App.RootFrame.Background = myLinearGradientBrush;
ApplicationBar.BackgroundColor = Color.FromArgb(255, 0, 138, 0);
}
}
}
catch
{
}
base.OnNavigatedTo(e);
}
请建议我,我该怎么做才能更改background
主题的Dark
。
等待回复。
由于
答案 0 :(得分:1)
试试这个:
XAML:
<toolkit:ListPicker x:Name="themelistPicker1" SelectionChanged="themelistPicker1_SelectionChanged">
<toolkit:ListPickerItem Content="Light"></toolkit:ListPickerItem>
<toolkit:ListPickerItem Content="Dark"></toolkit:ListPickerItem>
</toolkit:ListPicker>
CS:
public themes()
{
InitializeComponent();
linear = new LinearGradientBrush();
linear.StartPoint = new Point(0, 0);
linear.EndPoint = new Point(1, 1);
linear.GradientStops.Add(new GradientStop() { Color = Colors.Blue, Offset = 0.0 });
inear.GradientStops.Add(new GradientStop() { Color = Colors.Cyan, Offset = 0.25 });
linear.GradientStops.Add(new GradientStop() { Color = Colors.Blue, Offset = 0.75 });
linear.GradientStops.Add(new GradientStop() { Color = Colors.Purple, Offset = 0.1 });
myLinearGradientBrush = new LinearGradientBrush();
myLinearGradientBrush.StartPoint = new Point(0.5, 0.0);
myLinearGradientBrush.EndPoint = new Point(0.5, 1.0);
myLinearGradientBrush.GradientStops.Add(new GradientStop() { Color = Color.FromArgb(225, 164, 196, 0), Offset = 0.0 });
myLinearGradientBrush.GradientStops.Add(new GradientStop() { Color = Color.FromArgb(255, 96, 169, 23), Offset = 0.567 });
myLinearGradientBrush.GradientStops.Add(new GradientStop() { Color = Color.FromArgb(255, 0, 138, 0), Offset = 1.0 });
myLinearGradientBrush.Opacity = 50;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
if (settings.Contains("userData"))
{
string str = settings["userData"].ToString();
if (str == "Dark")
{
themelistPicker1.SelectedIndex = 1;
tblk_settings.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
tblk_theme.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
tblk_text.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
tblk_bg.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
themelistPicker1.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 80, 239));
themelistPicker1.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 0, 80, 239));
LayoutRoot.Background = linear;
App.RootFrame.Background = linear;
ApplicationBar.BackgroundColor = Colors.Blue;
}
else
{
themelistPicker1.SelectedIndex = 0;
tblk_settings.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
tblk_theme.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
tblk_text.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
tblk_bg.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
themelistPicker1.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
themelistPicker1.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
LayoutRoot.Background = myLinearGradientBrush;
App.RootFrame.Background = myLinearGradientBrush;
ApplicationBar.BackgroundColor = Color.FromArgb(255, 0, 138, 0);
}
}
base.OnNavigatedTo(e);
}
private void themelistPicker1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (themelistPicker1 != null && themelistPicker1.SelectedIndex > -1)
{
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
ListPickerItem lpi = (sender as ListPicker).SelectedItem as ListPickerItem;
string themename = lpi.Content.ToString();
if (!settings.Contains("userData"))
settings.Add("userData", themename);
else
settings["userData"] = themename;
settings.Save();
try
{
if (themename == "Dark")
{
tblk_settings.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
tblk_theme.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
tblk_text.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
tblk_bg.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
themelistPicker1.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 80, 239));
themelistPicker1.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 0, 80, 239));
LayoutRoot.Background = linear;
App.RootFrame.Background = linear;
ApplicationBar.BackgroundColor = Colors.Blue;
}
else
{
tblk_settings.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
tblk_theme.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
tblk_text.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
tblk_bg.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
themelistPicker1.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
themelistPicker1.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 0, 138, 0));
LayoutRoot.Background = myLinearGradientBrush;
App.RootFrame.Background = myLinearGradientBrush;
ApplicationBar.BackgroundColor = Color.FromArgb(255, 0, 138, 0);
}
}
catch { }
}
}