Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

WPF Striped Gradient Code Behind VB

Posted on 2014-01-23
2
Medium Priority
?
641 Views
Last Modified: 2014-01-23
So I am trying to apply a striped gradient to a rectangle from the code behind.  I know how to do it from XAML:

<LinearGradientBrush StartPoint="0,0" EndPoint="1,1" SpreadMethod="Repeat">
    <GradientStop Offset="0" Color="DarkRed"/>
    <GradientStop Offset="0.5" Color="DarkRed"/>
    <GradientStop Offset="0.5" Color="Black"/>
    <GradientStop Offset="1" Color="Black"/>

 <LinearGradientBrush.RelativeTransform>
        <ScaleTransform ScaleX="0.01" ScaleY="0.01"/>
    </LinearGradientBrush.RelativeTransform>
</LinearGradientBrush>

Open in new window


But I can't figure out how go get the RelativeTransform to work.  Here is my vb:

 Dim myBrush As New LinearGradientBrush()
        myBrush.SpreadMethod = GradientSpreadMethod.Repeat
        myBrush.GradientStops.Add(New GradientStop(Colors.DarkRed, 0.0))
        myBrush.GradientStops.Add(New GradientStop(Colors.DarkRed, 0.5))
        myBrush.GradientStops.Add(New GradientStop(Colors.Black, 0.5))
        myBrush.GradientStops.Add(New GradientStop(Colors.Black, 1.0))
        myBrush.RelativeTransform = ScaleTransform.ScaleXProperty

        rect0.Fill = myBrush

Open in new window


Any help on this would be appreciated.
0
Comment
Question by:G Scott
  • 2
2 Comments
 
LVL 1

Accepted Solution

by:
G Scott earned 0 total points
ID: 39805409
This did it:

   Dim myBrush As New LinearGradientBrush()

        myBrush.GradientStops.Add(New GradientStop(Colors.DarkRed, 0.0))
        myBrush.GradientStops.Add(New GradientStop(Colors.DarkRed, 0.5))
        myBrush.GradientStops.Add(New GradientStop(Colors.Black, 0.5))
        myBrush.GradientStops.Add(New GradientStop(Colors.Black, 1.0))
        'myBrush.RelativeTransform = ScaleTransform.ScaleXProperty
        Dim scale As New ScaleTransform(0.1, 0.1)
        myBrush.RelativeTransform = scale
        myBrush.SpreadMethod = GradientSpreadMethod.Repeat
        rect0.Fill = myBrush

Open in new window

0
 
LVL 1

Author Closing Comment

by:G Scott
ID: 39805410
I want to keep this open to help others.  I solved it using trial and error.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question