locked
Windows store apps - Linear gradient brush in c# RRS feed

  • Question

  • Hey,

    I have this stackpanel in my app:

    StackPanel sta = new StackPanel(){Width = 300};


    I want to set the Background property of it to a linear Gradient Brush.

     These are the two colors i want to use

    #FF1AD6FD

    #1D62F0 

    The angle i want is 90 degrees. 

    How do  i do this in c#?

    Thank you

    Wednesday, November 27, 2013 5:07 AM

Answers

  • Hello kalel111, 

    try this: 

                GradientStopCollection c = new GradientStopCollection();
    
                GradientStop gryellow = new GradientStop();
                gryellow.Color = Color.FromArgb(100, 26, 214, 253);
                gryellow.Offset = 0.0;
    
                GradientStop grgreen = new GradientStop();
                grgreen.Color = Color.FromArgb(100, 29, 98, 240);
                grgreen.Offset = 1.0;
                c.Add(grgreen);
                c.Add(gryellow);
                LinearGradientBrush br = new LinearGradientBrush(c, 90);
                stackpanel1.Background = br;
    • Marked as answer by kalel111 Wednesday, November 27, 2013 5:53 AM
    Wednesday, November 27, 2013 5:34 AM

All replies

  • Hello kalel111, 

    try this: 

                GradientStopCollection c = new GradientStopCollection();
    
                GradientStop gryellow = new GradientStop();
                gryellow.Color = Color.FromArgb(100, 26, 214, 253);
                gryellow.Offset = 0.0;
    
                GradientStop grgreen = new GradientStop();
                grgreen.Color = Color.FromArgb(100, 29, 98, 240);
                grgreen.Offset = 1.0;
                c.Add(grgreen);
                c.Add(gryellow);
                LinearGradientBrush br = new LinearGradientBrush(c, 90);
                stackpanel1.Background = br;
    • Marked as answer by kalel111 Wednesday, November 27, 2013 5:53 AM
    Wednesday, November 27, 2013 5:34 AM
  • Yes this  works!


    Wednesday, November 27, 2013 5:53 AM