Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 主题背景不会从wp8 c中的“设置”页面更改_C#_Windows Phone 8_Themes - Fatal编程技术网

C# 主题背景不会从wp8 c中的“设置”页面更改

C# 主题背景不会从wp8 c中的“设置”页面更改,c#,windows-phone-8,themes,C#,Windows Phone 8,Themes,对于我的windows phone应用程序,我创建了两个主题黑暗和光明,当我从listpicker中选择光明时,我的光明主题如下: 但我从listpicker中选择Dark,主题背景不改变,只有前景改变,即: 下面是listpicker选择更改方法: private void themelistPicker1_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (themelistPicker1 != nul

对于我的windows phone应用程序,我创建了两个主题黑暗和光明,当我从listpicker中选择光明时,我的光明主题如下:

但我从listpicker中选择Dark,主题背景不改变,只有前景改变,即:

下面是listpicker选择更改方法:

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 { }
    }
}  
下面是主题页面的构造器:

其中,我为暗主题定义了两个灰色“线性”,为亮主题定义了myLinearGradientBrush,下面是导航到方法:

请建议我,我能做些什么来改变黑暗主题的背景。 等待答复

谢谢

试试这个:

XAML:


我已经尝试过了,将背景颜色更改为黑色,用于明暗主题。我已经实现了上述内容,然后我已经回答了。它起作用了。通过上述方法删除代码后重试。
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
    { 

    }

}
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);
}
        <toolkit:ListPicker x:Name="themelistPicker1" SelectionChanged="themelistPicker1_SelectionChanged">
            <toolkit:ListPickerItem Content="Light"></toolkit:ListPickerItem>
            <toolkit:ListPickerItem Content="Dark"></toolkit:ListPickerItem>
        </toolkit:ListPicker>
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 { }
    }
}