I have a Canvas
with the following XAML definition:
<Canvas Height="201" VerticalAlignment="Top"
Name="myCanvas"
KeyDown="KeyEvent" >
<local:MyGlyphsElement x:Name="mge" />
<Line Name="myLine" Stroke="Blue" StrokeThickness="2"></Line>
</Canvas>
In the code-behind file for the MyGlyphsElement
control, how can I access myLine
and myCanvas
? (MyGlyphsElement
is derived from FrameworkElement
.)
My purpose is to be able to add controls at runtime to myCanvas
children as well as manipulate myLine
properties such as stroke width, etc.
EDIT:
public partial class MyGlyphsElement: FrameworkElement
protected override void OnRender(DrawingContext drawingContext)
{
base.OnRender(drawingContext); // Good practice.
...
Canvas cp = (Canvas)this.Parent;
// Now what? How do I access myLine?