Answered by:
Changing Grid Background with LinearGradientBrush Using VB

Question
-
I'm looking for an example on how to change a grid's background in code behind, using Visual Basic. I can find examples in C##, but I don't know how to convert these examples to VB.
The Linear Gradient for the square-shaped grid will have only 2 colors: #FF37A4B4 and #FF250988, with an Angle of -45. Any pointers appreciated.
Saturday, October 26, 2013 4:15 AM
Answers
-
Hello David,
try this:
Dim br As New LinearGradientBrush() br.StartPoint = New Point(0, 0) br.EndPoint = New Point(1, 1) Dim gryellow As New GradientStop() gryellow.Color = Color.FromArgb(100, 55, 164, 180) gryellow.Offset = 0.0 br.GradientStops.Add(gryellow) Dim grgreen As New GradientStop() grgreen.Color = Color.FromArgb(100, 37, 9, 136) grgreen.Offset = 1.0 br.GradientStops.Add(grgreen) //your grid name grid1.Background = br
- Marked as answer by Jamles HezModerator Friday, November 8, 2013 3:13 AM
Saturday, October 26, 2013 4:42 AM -
Hmmm. I discovered that a foundational grid with a dark background was affecting the resulting coloration of grids within. The opacity of the interior grids are 100% so it's not clear to me why the back grid is bleeding through.
- Marked as answer by Jamles HezModerator Friday, November 8, 2013 3:13 AM
Saturday, October 26, 2013 4:02 PM
All replies
-
Hello David,
try this:
Dim br As New LinearGradientBrush() br.StartPoint = New Point(0, 0) br.EndPoint = New Point(1, 1) Dim gryellow As New GradientStop() gryellow.Color = Color.FromArgb(100, 55, 164, 180) gryellow.Offset = 0.0 br.GradientStops.Add(gryellow) Dim grgreen As New GradientStop() grgreen.Color = Color.FromArgb(100, 37, 9, 136) grgreen.Offset = 1.0 br.GradientStops.Add(grgreen) //your grid name grid1.Background = br
- Marked as answer by Jamles HezModerator Friday, November 8, 2013 3:13 AM
Saturday, October 26, 2013 4:42 AM -
Thanks, Khant! That helps a lot! I notice, though, that the resulting colors look a lot darker than I have in design time.
Here's the XAML settings of the grid in design time:
<Grid.Background> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <LinearGradientBrush.RelativeTransform> <CompositeTransform CenterY="0.5" CenterX="0.5" Rotation="-46.848"/> </LinearGradientBrush.RelativeTransform> <GradientStop Color="#FF37A4B4"/> <GradientStop Color="#FF250988" Offset="1"/> </LinearGradientBrush> </Grid.Background>
Odd that the #FF37A4B4 translated in RGBA as 55-164-180-100 within the Properties, but I wonder why the resulting colors are so much darker when I use the VB code behind to change it.
Thanks again.
- Edited by David VB2005 Saturday, October 26, 2013 3:36 PM
Saturday, October 26, 2013 3:31 PM -
Hmmm. I discovered that a foundational grid with a dark background was affecting the resulting coloration of grids within. The opacity of the interior grids are 100% so it's not clear to me why the back grid is bleeding through.
- Marked as answer by Jamles HezModerator Friday, November 8, 2013 3:13 AM
Saturday, October 26, 2013 4:02 PM