Search code examples
c#silverlightsilverlight-4.0opacitystroke

In Silverlight 4: how to set the Opacity of a Stroke programmatically?


I want to set the opacity of a Stroke which is obtained from a user drawing on the screen. I can get the drawing, size, outline of the stroke to set but not the Opacity of it.

This is my code

StylusPointCollection spTemp = e.StylusDevice.GetStylusPoints(MyIP);
        tempStroke.StylusPoints.Add(spTemp);

        tempStroke.DrawingAttributes.Color = Colors.Red;
        tempStroke.DrawingAttributes.OutlineColor = Colors.Black;

        tempStroke.DrawingAttributes.Width = BrushSize.Value;
        tempStroke.DrawingAttributes.Height = BrushSize.Value;

        MyIP.Strokes.Add(tempStroke);

Any help is appreciated

Simple Code


Solution

  • Set the alpha value on the color. eg for an opacity of +-0.5 and color red:

    tempStroke.DrawingAttributes.Color = Colors.FromArgb(125,255,0,0);