Solved

WPF Striped Gradient Code Behind VB

Posted on 2014-01-23
2
556 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
Comment Utility
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
Comment Utility
I want to keep this open to help others.  I solved it using trial and error.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now