Hello all,
In silverlight Canvas class (with Reflector) has very simple implementation: 3 attached dependency properties (Left, Top, ZIndex) and 2 ovverides of MeasureOverride and ArrangeOverride methods which do nothing special.
But if i use my implementation like:
class MyCanvas : Panel { /* Top and Left dependency properties implementation */ }
And then use MyCanvas in XAML like standard Canvas. That's not working as expected (i see the empty screen).
How Canvas was implemented?
-- Additional code: MyCanvas.cs
public class MyCanvas : Panel
{
public static double GetTop(DependencyObject obj)
{
return (double)obj.GetValue(TopProperty);
}
public static void SetTop(DependencyObject obj, double value)
{
obj.SetValue(TopProperty, value);
}
// Using a DependencyProperty as the backing store for Top. This enables animation, styling, binding, etc...
public static readonly DependencyProperty TopProperty =
DependencyProperty.RegisterAttached("Top", typeof(double), typeof(MyCanvas), new PropertyMetadata(0.0));
public static double GetLeft(DependencyObject obj)
{
return (double)obj.GetValue(LeftProperty);
}
public static void SetLeft(DependencyObject obj, double value)
{
obj.SetValue(LeftProperty, value);
}
// Using a DependencyProperty as the backing store for Left. This enables animation, styling, binding, etc...
public static readonly DependencyProperty LeftProperty =
DependencyProperty.RegisterAttached("Left", typeof(double), typeof(MyCanvas), new PropertyMetadata(0.0));
}
Used in XAML like:
<local:MyCanvas>
<Rectangle
local:MyCanvas.Left="10"
local:MyCanvas.Top="10"
Width="100"
Height="100"
Fill="Black" />
</local:MyCanvas>
if change MyCanvas to standard Canvas, i can view black-filled rectangle at position 10,10.
<Canvas>
<Rectangle
Canvas.Left="10"
Canvas.Top="10"
Width="100"
Height="100"
Fill="Black" />
</Canvas>