Hi Guys
We are drawing annotation lines on our charts using the following
<visuals:HorizontalLineAnnotation HorizontalAlignment="Stretch" AnnotationCanvas="BelowChart" IsHidden="{Binding IsUpperThresholdVisible, Converter={StaticResource InvertBoolean}}" Stroke="Gainsboro" StrokeThickness="0.75" XAxisId="IndicatorXAxis" YAxisId="StandardAxis" Y1="{Binding UpperThreshold}"> <visuals:AnnotationLabel TextFormatting="0" FontSize="11" FontFamily="Segoe UI" Foreground="Black" FontWeight="Bold" LabelPlacement="Axis" /> </visuals:HorizontalLineAnnotation> <visuals:HorizontalLineAnnotation HorizontalAlignment="Stretch" AnnotationCanvas="BelowChart" IsHidden="{Binding IsLowerThresholdVisible, Converter={StaticResource InvertBoolean}}" Stroke="Gainsboro" StrokeThickness="0.75" XAxisId="IndicatorXAxis" YAxisId="StandardAxis" Y1="{Binding LowerThreshold}"> <visuals:AnnotationLabel TextFormatting="0" FontSize="11" Foreground="Black" FontFamily="Segoe UI" FontWeight="Bold" LabelPlacement="Axis" /> </visuals:HorizontalLineAnnotation>
The y1 value for each is set in Binding initially and once rendered can be manipulated by the user using a numeric up-down for each line.
Our problem is that when the lines are initially rendered they do not always display with the correct thickness (see Annotation Too Thin.png attached). When the line is subsequently moved using the numeric up-down to change its Y1 value the line then shows at the correct thickness.
We have tried snap to pixels to no effect and looked for, but did not find, anti-aliasing for annotation lines.
Could you point us in the right direction for this one please?
Thanks in advance
Ian Carson
- Ian Carson asked 10 years ago
- You must login to post comments
If you set the line thickness to 0.75 (which you have), then WPF will try to render it between pixels. The result will be it will fade (become thicker/thinner) as you move it, as it spans pixels. Sometimes WPF will render it inside 1 pixel, sometimes spanning 2.
The best result to get a thin sharp line is to set line thickness to 1.0.
- Andrew Burnett-Thompson answered 10 years ago
-
Hi Andrew Would that it were that simple! :) I just tried 1px and the -20 line (as per the previous attachments) disappears completely. Move it to -19 or -21 and it reappears (as a 1px line). This issue is not restricted to the negative value lines either. On other charts where the annotation Y1 value is positive I'm seeing the same issue. Not sure what's happening here at all. Regards Ian
-
Ok so the lines disappearing also sounds like SnapToDevicePixels / UseLayoutRounding. WPF does strange things. Question: can you reproduce this in any of our examples? There is nothing magic we are doing here, just displaying a line on a canvas! Andrew
-
Hi Andrew It's not a perfect solution but by setting the Margin in the line annotation to (0,0.5,0,0.5) it solves the problem for where we want the lines to appear. SnapToDevicePixels not set, UseLayoutRounding not set. Regards Ian
-
Ah, I remember seeing this elsewhere. Before when we were drawing Gridlines on the WPF canvas (now we use bitmaps), we had to set the pixel offset to 0.5 (e.g. draw at X=10.5, 20.5 not 10, 20) and set SnapsToDevicePixels/UseLayoutRounding=true to get the lines sharp. Beats me why in WPF you need 0.5 pixels to make a line snap to the nearest pixel but that seemed to work. You have discovered the same! Glad you got the problem sorted and sorry I couldn't be more help. Andrew
-
Hi Andrew No problem. Thanks for the followup. Regards Ian
- You must login to post comments
Please login first to submit.