Click here to Skip to main content
15,994,794 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello. I would like to make a button which can change color of all background grids in my app.

I just know that this function changes color of actual grid:

LayoutRoot.Background = new SolidColorBrush(Colors.Blue);



Now, how to store this color value as a static value? I mean, after click, color value will be stored.

How to retrieve this value while every new page loads?

How can I store this value in isolated storage?

I know I should make a class with a static variable.
I am newbie in programming, so can someone tell me how to program page, where button will be placed and class.vb page?
Maybe it sounds weird, but I understand everything better basing on examples.
Posted
Updated 15-Dec-12 7:01am
v2
Comments
StackQ 15-Dec-12 13:40pm    
provide code,and comment at place where u want solution.
Dawid Lis 15-Dec-12 13:47pm    
This is the page where button should be placed

Imports System.Windows.Media
Partial Public Class Settings
Inherits PhoneApplicationPage

Public Sub New()
InitializeComponent()
End Sub

Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
LayoutRoot.Background = New SolidColorBrush(Colors.Red)
End Sub
End Class

About the class; actually it's empty, because I'm not sure what I should place there;

Public Class Kolor


End Class
StackQ 15-Dec-12 13:54pm    
r u want to store colour name or it's value?Why?Bcoz u r giving manually:-Colors.Red
Then u can do it like:-

Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
LayoutRoot.Background = New SolidColorBrush(Colors.Red)
Dim Color as String="Red" //actually what u want i m not getting
End Sub

Elaborate more,and why u want to use class?
Dawid Lis 15-Dec-12 14:00pm    
Ok, I'll try to explain it.
I got such a help from microsoft forum (about class).
It's kind of a theme changer. There will be a few buttons, each can change color of all grids in all pages to this one color he applied. ex. user clicks button white, it changes all backgrounds colors in all pages for white. etc
I need to store somewhere this color variable, when user restarts app, variable restores and all grids change automatically.
I was thinking about loading page and everytime the page loads, the grid reads color from "somewhere" and applies it to its grid.

If you have any better idea, please share :)
StackQ 15-Dec-12 14:26pm    
check again

1 solution

1st:-Make a function to generate random color

VB
Private Function CreateRandomColor() As Color
    Dim randonGen As New Random()
    Dim randomColor As Color = Color.FromArgb(randonGen.[Next](255), randonGen.[Next](255), randonGen.[Next](255))

    Return randomColor
End Function



Imports System.Windows.Media
Partial Public Class Settings
    Inherits PhoneApplicationPage

    Public Sub New()
        InitializeComponent()
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
Dim color As Color 
color= CreateRandomColor()
 While (color != White or Red or Blue or Green) 'Specify color names u want 
        LayoutRoot.Background = New SolidColorBrush(color)
color = CreateRandomColor()
End While
    End Sub
End Class
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900