Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have a customInkCanvas which inherits from InkCanvas.

I have an image that I wish to place on the InkCanvas.

For the normal InkCanvas, this works:
C#
Canvas.SetTop(image, y);
Canvas.SetLeft(image, x);
InkCanvas.Children.Add(image);

However, for CustomInkCanvas, the above fails. So how do I position an element on the CustomInkCanvas?

I'm guessing that Top,Left, etc, are attached properties to InkCanvas and are not passed down to customInkCanvas.

Any help will be really appreciated!

Edit: I've realized this is actually a two-part question:
1. I missed that InkCanvas does NOT inherit from Canvas, so I was needing to replace Canvas.SetTop() with InkCanvas.SetTop(). Having learned that, is there a way to
2. Inherit or pass-down attached properties?

Thanks
Posted
Updated 25-May-14 7:03am
v3
Comments
karthik Udhayakumar 25-May-14 6:58am    
Where is your code?just quick click improve question and paste your code for better answers from the community.
Sergey Alexandrovich Kryukov 25-May-14 10:54am    
The question is: what have you done to your inherited CustomInkCanvas to screw up the basic functionality of InkCanvas? A complete but short code sample would help. Please see: SSCCE.
—SA

1 solution

Attached properties are not inherited in the way members or methods of classes are inherited.
When we talk about attached properties being inherited we usually refer to the value of an attached property set on a parent element of the visual tree also applies to the children of that node (unless overridden with a new value).

Think of the Grid.Row attached property for example, you can set if for Labels and Checkboxes and so on, but that doesn't mean that these controls somehow inherit the attached property from Grid.

Instead, it's the responsibility of the Grid class to check if the Grid.Row value is set (or use the default value) when doing layout and use the that value to correctly position the element.

In your example;
C#
InkCanvas.SetTop(image, y);
InkCanvas.SetLeft(image, x);
InkCanvas.Children.Add(image);


The variables x and y are attached to image, and then InkCanvas looks at those during it's MeasureOverride and ArrangeOverride passes. This means that if your CustomInkCanvas not overrides those methods from InkCanvas then the values are not observed.

Hope this helps,
Fredrik
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900