Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7006623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:30:04+00:00 2026-05-27T21:30:04+00:00

I’m a fairly experienced .NET desktop developer, but I’m new to Silverlight. I’m trying

  • 0

I’m a fairly experienced .NET desktop developer, but I’m new to Silverlight. I’m trying to convert an iOS application to a Silverlight app.

The app is basically a list of items that are built using data pulled from a database. This data includes a large number of label texts as well as foreground and background color information. Each object is its own user control. It consists of a Border control (for background coloring and rounded edges) with a Grid inside. All of my label controls (TextBlocks) are inside of the Grid.

Each of these color values (foreground and background) come out of the database as a comma-delimited string (i.e., “{r},{g},{b}”).

So, I convert those values to actual color objects in code. Then, I set the foreground property of my labels to this color.

All of this (label text assignments and foreground color) is working very well. What’s NOT working is converting the background color into a linear gradient brush. I’m currently using the color from the database as a “base” color and calculating a 4-color gradient from this color. (The numbers aren’t important, but I adjust the RGB values to 1.4, 1.2, 0.8 and 0.6 of the base color).

Here’s the code to create the custom linear gradient brush:

Friend Function CalculateColorsFromBaseColor(ByVal baseColor As Color) As List(Of Color)
    Dim retList As New List(Of Color)
    Dim r As Byte = baseColor.R
    Dim g As Byte = baseColor.G
    Dim b As Byte = baseColor.B
    retList.Add(New Color With {.R = If(r * 1.4 > 255, 255, r * 1.4), .G = If(g * 1.4 > 255, 255, g * 1.4), .B = If(b * 1.4 > 255, 255, b * 1.4)})
    retList.Add(New Color With {.R = If(r * 1.2 > 255, 255, r * 1.2), .G = If(g * 1.2 > 255, 255, g * 1.2), .B = If(b * 1.2 > 255, 255, b * 1.2)})
    retList.Add(New Color With {.R = If(r * 0.8 > 255, 255, r * 0.8), .G = If(g * 0.8 > 255, 255, g * 0.8), .B = If(b * 0.8 > 255, 255, b * 0.8)})
    retList.Add(New Color With {.R = If(r * 0.6 > 255, 255, r * 0.6), .G = If(g * 0.6 > 255, 255, g * 0.6), .B = If(b * 0.6 > 255, 255, b * 0.6)})
    Return retList
End Function

Friend Function CalculateLinearGradientBrushFromBaseColor(ByVal baseColor As Color) As LinearGradientBrush
    Dim lgb As New LinearGradientBrush With {.StartPoint = New Point(0.5, 0), .EndPoint = New Point(0.5, 1)}
    Dim colors As List(Of Color) = CalculateColorsFromBaseColor(baseColor)
    lgb.GradientStops.Add(New GradientStop With {.Color = colors.Item(0), .Offset = 0.0})
    lgb.GradientStops.Add(New GradientStop With {.Color = colors.Item(1), .Offset = 0.5})
    lgb.GradientStops.Add(New GradientStop With {.Color = colors.Item(2), .Offset = 0.5})
    lgb.GradientStops.Add(New GradientStop With {.Color = colors.Item(3), .Offset = 1.0})
    Return lgb
End Function

Here’s the code for how I’m trying to incorporate this at runtime:

Dim backColorString As String = iCase.CaseColor
Dim backColorRGB As String() = backColorString.Split(",")
Dim backColor As Color = Color.FromArgb(255, CInt(backColorRGB(0)), CInt(backColorRGB(1)), CInt(backColorRGB(2)))
caseCell.BackgroundBorder.Background = caseCell.CalculateLinearGradientBrushFromBaseColor(backColor)

When I set a background gradient manually in XAML at design-time, it appears correctly. When I try to do it from the code-behind, it appears that I get no background at all. (When the overall page’s background is white, so is the color of my user control. When black, it’s black. So, it appears that the background of the user control ends up transparent.)

Trying to debug this, I’ve added the following code around my background assignment:

'' Trying to see what the background values are prior to setting it
For Each iStop As GradientStop In CType(caseCell.BackgroundBorder.Background, LinearGradientBrush).GradientStops
    MessageBox.Show(String.Format("iStop Color: ({0},{1},{2})", iStop.Color.R, iStop.Color.G, iStop.Color.B))
Next
'' Setting the background
caseCell.BackgroundBorder.Background = caseCell.CalculateLinearGradientBrushFromBaseColor(backColor)
'' Checking the values after setting
For Each iStop As GradientStop In CType(caseCell.BackgroundBorder.Background, LinearGradientBrush).GradientStops
    MessageBox.Show(String.Format("iStop Color: ({0},{1},{2})", iStop.Color.R, iStop.Color.G, iStop.Color.B))
Next

All of the message box results are as expected, but still, I get no background gradient. Anybody have any idea what’s going on?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:30:04+00:00Added an answer on May 27, 2026 at 9:30 pm

    STUPID, STUPID, STUPID!!!!!

    So, apparently, by not setting the alpha values here:

    Friend Function CalculateColorsFromBaseColor(ByVal baseColor As Color) As List(Of Color)
        Dim retList As New List(Of Color)
        Dim r As Byte = baseColor.R
        Dim g As Byte = baseColor.G
        Dim b As Byte = baseColor.B
        retList.Add(New Color With {.R = If(r * 1.4 > 255, 255, r * 1.4), .G = If(g * 1.4 > 255, 255, g * 1.4), .B = If(b * 1.4 > 255, 255, b * 1.4)})
        retList.Add(New Color With {.R = If(r * 1.2 > 255, 255, r * 1.2), .G = If(g * 1.2 > 255, 255, g * 1.2), .B = If(b * 1.2 > 255, 255, b * 1.2)})
        retList.Add(New Color With {.R = If(r * 0.8 > 255, 255, r * 0.8), .G = If(g * 0.8 > 255, 255, g * 0.8), .B = If(b * 0.8 > 255, 255, b * 0.8)})
        retList.Add(New Color With {.R = If(r * 0.6 > 255, 255, r * 0.6), .G = If(g * 0.6 > 255, 255, g * 0.6), .B = If(b * 0.6 > 255, 255, b * 0.6)})
        Return retList
    End Function
    

    I was making transparent colors.

    STUPID, STUPID, STUPID!!! Here’s the working code:

    Friend Function CalculateColorsFromBaseColor(ByVal baseColor As Color) As List(Of Color)
        Dim retList As New List(Of Color)
        Dim r As Byte = baseColor.R
        Dim g As Byte = baseColor.G
        Dim b As Byte = baseColor.B
        retList.Add(New Color With {.A = 255, .R = If(r * 1.4 > 255, 255, r * 1.4), .G = If(g * 1.4 > 255, 255, g * 1.4), .B = If(b * 1.4 > 255, 255, b * 1.4)})
        retList.Add(New Color With {.A = 255, .R = If(r * 1.2 > 255, 255, r * 1.2), .G = If(g * 1.2 > 255, 255, g * 1.2), .B = If(b * 1.2 > 255, 255, b * 1.2)})
        retList.Add(New Color With {.A = 255, .R = If(r * 0.8 > 255, 255, r * 0.8), .G = If(g * 0.8 > 255, 255, g * 0.8), .B = If(b * 0.8 > 255, 255, b * 0.8)})
        retList.Add(New Color With {.A = 255, .R = If(r * 0.6 > 255, 255, r * 0.6), .G = If(g * 0.6 > 255, 255, g * 0.6), .B = If(b * 0.6 > 255, 255, b * 0.6)})
        Return retList
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.