Solved

WPF Striped Gradient Code Behind VB

Posted on 2014-01-23
2
572 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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
update textboxes with Streamreader 21 47
Need a starter for ETL protocol? 4 57
write xml in vb.net 2 24
How to open form using item in Listbox. 8 21
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

777 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