Solved

WPF Striped Gradient Code Behind VB

Posted on 2014-01-23
2
613 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

627 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