Skip to main content
Home Forums Silverlight Programming Report a Silverlight Bug Problem in drawing 1px line in InkPresenter with Stroke
3 replies. Latest Post by StefanWick on December 17, 2008.
(0)
rorbbin
Member
2 points
5 Posts
12-15-2008 3:54 AM |
I have a problem in drawing 1px line in InkPresenter using Stroke. I doubt there is something inperfect with its mechanism in rendering line. I have set my stroke's DrawingAttributes as follow:
newStroke.DrawingAttributes.Color = Colors.Black; newStroke.DrawingAttributes.Height = 0.5; // 1 and 2 to be test newStroke.DrawingAttributes.Width = 0.5; newStroke.DrawingAttributes.OutlineColor = Colors.Transparent;
and I have get the result as follow picture compare with the Windows paint:
if not displayed, image url:Show image
As shown in picture, silverlight renders the 0.5px, 1px and 2px lines with no diffirence but color changing from lightgray to black. What I want is the line rendered in paint as lower part of the picture. How Can I solve this problem. The following is the code I written:
Page.xaml
<UserControl x:Class="HelloWorld.Page" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="406" Height="404"> <Grid x:Name="LayoutRoot" Background="Black"> <InkPresenter x:Name="inkPresenter" Width="400" Height="400" Background="White" MouseLeftButtonDown="inkPresenter_MouseLeftButtonDown" MouseLeftButtonUp="inkPresenter_MouseLeftButtonUp" MouseMove="inkPresenter_MouseMove"/> </Grid></UserControl>
Page.xaml.cs
public partial class Page : UserControl { InkPresenter curInkPre = null; Cursor oldCursor = Cursors.Arrow; Stroke newStroke = null; public Page() { InitializeComponent(); SetBoundary(inkPresenter); } private void inkPresenter_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { curInkPre = e.OriginalSource as InkPresenter; curInkPre.CaptureMouse(); oldCursor = curInkPre.Cursor; curInkPre.Cursor = Cursors.Stylus; newStroke = new Stroke(); newStroke.StylusPoints.Add(e.StylusDevice.GetStylusPoints(curInkPre)); newStroke.DrawingAttributes.Color = Colors.Black; newStroke.DrawingAttributes.Height = 2; newStroke.DrawingAttributes.Width = 2; newStroke.DrawingAttributes.OutlineColor = Colors.Transparent; curInkPre.Strokes.Add(newStroke); } private void inkPresenter_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { newStroke = null; InkPresenter ink = e.OriginalSource as InkPresenter; ink.Cursor = oldCursor; } private void inkPresenter_MouseMove(object sender, MouseEventArgs e) { if (newStroke != null) { newStroke.StylusPoints.Add(e.StylusDevice.GetStylusPoints(curInkPre)); } } private void SetBoundary(InkPresenter ink) { RectangleGeometry rectGeo = new RectangleGeometry(); rectGeo.Rect = new Rect(0, 0, ink.ActualWidth, ink.ActualHeight); ink.Clip = rectGeo; } }
StefanWick
Contributor
2864 points
438 Posts
12-16-2008 2:57 AM |
This picture didn't come through. Also the URL didn't work for me. Can you update this?
Thanks, Stefan Wick
12-16-2008 3:49 AM |
It works fine as I click. If you can tell me your email and I wil sent it to you.
12-17-2008 2:25 AM |
Please send it to swick at microsoft.com.