简体   繁体   中英

theme backgroung not change from the settings page in wp8 c#

For my windows phone application I have create two theme Dark and Light and When I select Light from listpicker the my Light theme is below:

在此处输入图片说明

But I select Dark from listpicker , theme background is not change only foreground is change, ie below:

在此处输入图片说明

Below is listpicker selectionchange method:

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 { }
    }
}  

below is the constructor of theme page:

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
    { 

    }

}

where I defined two Gredients 'linear' for Dark theme and myLinearGradientBrush for Light theme And below is OnNavigatedTo method:

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);
}

Kindly suggest me, what can I do to change the background of the Dark theme. Waiting for reply.

Thanks

try this:

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 { }
    }
}

轻主题黑暗主题

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM