Answered by:
How do I make a rectangle change color when tapped?

Question
-
I'm trying to make a rectangle that cycles through 4 colors when tapped, going to the next color each time its tapped, using VB.
Here's the colors:
- #91B49C
- #667E6D
- #485A4E
- #0E1210
However, I can't seem to get the brushes to work.
How should I go about doing this?
Saturday, September 27, 2014 11:47 PM
Answers
-
Did you import Windows.UI? Your code works fine with me.
Imports Windows.UI ' The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238 ''' <summary> ''' An empty page that can be used on its own or navigated to within a Frame. ''' </summary> Public NotInheritable Class MainPage Inherits Page Private Sub Button_Click(sender As Object, e As RoutedEventArgs) Dim mySolidColorBrush As New SolidColorBrush() ' Describes the brush's color using RGB values. ' Each value has a range of 0-255. mySolidColorBrush.Color = Color.FromArgb(255, 0, 0, 255) myRgbRectangle.Fill = mySolidColorBrush End Sub End Class
--James
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.- Marked as answer by Clayton Ramsey Monday, September 29, 2014 5:41 PM
Monday, September 29, 2014 1:53 AMModerator
All replies
-
Hi, Clayton Ramsey.
You can create your custom control, which will have some collection with your brushes and when user tapped - you set next brush for her background.
OR you can create custom control which inheritance by button and override button style which will contains only rectangle and when user tap - change background color.Regards, Nikita.
Sunday, September 28, 2014 7:22 AM -
Hi Clayton,
As I kown Rectangle class can be set background by Fill Property.
You may want to manually switch the color by your code to fill different color each time your tapped event fired.
Binding color base on the click time is also a possibly solution.
--James
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.Sunday, September 28, 2014 9:27 AMModerator -
I think my problem is with the setting of the colors themselves. An article I found said to do this:
Dim mySolidColorBrush As New SolidColorBrush() ' Describes the brush's color using RGB values. ' Each value has a range of 0-255. mySolidColorBrush.Color = Color.FromArgb(255, 0, 0, 255) myRgbRectangle.Fill = mySolidColorBrush
However, Visual Studio will not allow me to set my Solid Color Brushes to anything.
Sorry if this is confusing.
Sunday, September 28, 2014 8:10 PM -
Did you import Windows.UI? Your code works fine with me.
Imports Windows.UI ' The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238 ''' <summary> ''' An empty page that can be used on its own or navigated to within a Frame. ''' </summary> Public NotInheritable Class MainPage Inherits Page Private Sub Button_Click(sender As Object, e As RoutedEventArgs) Dim mySolidColorBrush As New SolidColorBrush() ' Describes the brush's color using RGB values. ' Each value has a range of 0-255. mySolidColorBrush.Color = Color.FromArgb(255, 0, 0, 255) myRgbRectangle.Fill = mySolidColorBrush End Sub End Class
--James
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.- Marked as answer by Clayton Ramsey Monday, September 29, 2014 5:41 PM
Monday, September 29, 2014 1:53 AMModerator -
Did you import Windows.UI? Your code works fine with me.
Imports Windows.UI ' The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238 ''' <summary> ''' An empty page that can be used on its own or navigated to within a Frame. ''' </summary> Public NotInheritable Class MainPage Inherits Page Private Sub Button_Click(sender As Object, e As RoutedEventArgs) Dim mySolidColorBrush As New SolidColorBrush() ' Describes the brush's color using RGB values. ' Each value has a range of 0-255. mySolidColorBrush.Color = Color.FromArgb(255, 0, 0, 255) myRgbRectangle.Fill = mySolidColorBrush End Sub End Class
--James
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.Monday, September 29, 2014 5:41 PM