Bugzilla – Bug 324964
Canvas.Top and Canvas.Left not obeyed
Last modified: 2007-11-13 13:32:57 UTC
---- Reported by alan.mcgovern@gmail.com 2007-08-02 14:35:11 MST ---- When i add an instance of this class to my canvas, it always draws from 0,0 as opposed to Canvas.Top and Canvas.Left. I assume it shouldn't do this public class SelectionRectangle : Control { private Rectangle rect; public SelectionRectangle() :base() { // Notice i just instantiate a rectangle. // The 'SelectionRectangle' that i instantiate is then // added to a canvas InitializeFromXaml("<Rectangle Name=\"Rect\" />"); rect = (Rectangle)FindName("Rect"); rect.Opacity = 0.33; rect.Fill = new SolidColorBrush(Colors.Blue); rect.Stroke = new SolidColorBrush(Colors.Green); rect.StrokeDashArray = new double[] {5, 5 }; rect.StrokeThickness = 2; SetValue<int>(ZIndexProperty, int.MaxValue); } public override object GetValue (DependencyProperty property) { return rect.GetValue(property); } public override void SetValue<T> (DependencyProperty property, T obj) { rect.SetValue<T>(property, obj); } } Unknown operating system unknown. Setting to default OS "Other".
The supplied code doesn't run on Silverlight 1.1. This fragment: InitializeFromXaml("<Rectangle Name=\"Rect\" />"); rect = (Rectangle)FindName("Rect"); always results in a null rect (throwing a NullReferenceException at the next line). Changing the lines for: rect = (Rectangle) InitializeFromXaml("<Rectangle Name=\"Rect\" />"); does return a Rectangle instance. Anyway setring Canvas.Left and/or Canvas.Top works in both Moonlight and Silverlight.