Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I draw a "soft" line in WPF (presumably using a LinearGradientBrush)?
    primarykey
    data
    text
    <p>I'm trying to draw a line with soft edges, regardless of the slope. </p> <p>Here's the code I have so far: </p> <pre><code>&lt;Line HorizontalAlignment="Stretch" VerticalAlignment="Center" Stretch="Uniform" StrokeThickness="5" X1="0" Y1="0" X2="1" Y2="0"&gt; &lt;Shape.Stroke&gt; &lt;LinearGradientBrush StartPoint="0,0" EndPoint="0,1"&gt; &lt;GradientStop Color="Transparent" Offset="0" /&gt; &lt;GradientStop Color="Green" Offset="0.5" /&gt; &lt;GradientStop Color="Transparent" Offset="1" /&gt; &lt;/LinearGradientBrush&gt; &lt;/Shape.Stroke&gt; &lt;/Line&gt; </code></pre> <p>This makes sense to me, since the line is horizontal, and the linear gradient is vertical, with the edges being transparent and the middle of the line being solid green. </p> <p>The result is pleasing:<br> <a href="http://img15.imageshack.us/img15/4108/horizontalsoftline.png">http://img15.imageshack.us/img15/4108/horizontalsoftline.png</a><br> Zoomed in so you can see the gradient:<br> <a href="http://img225.imageshack.us/img225/5027/horizontalsoftlinezoomeb.png">http://img225.imageshack.us/img225/5027/horizontalsoftlinezoomeb.png</a> </p> <p>However, when the line is no longer horizontal, the gradient is calculated based on the line's bounding rectangle, rather than on the geometry of the line itself. The result is a slanted line that is shaded vertically, instead of the gradient being perpendicular to the line:<br> <a href="http://img183.imageshack.us/img183/7250/slantedsoftline.png">http://img183.imageshack.us/img183/7250/slantedsoftline.png</a> </p> <p>Does anyone know how WPF handles soft edges? I can't find anything on Google or MSDN, and I know there is a way to do this somewhow...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload