Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

WPF Striped Gradient Code Behind VB

Posted on 2014-01-23
2
Medium Priority
?
633 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
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…

715 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