Note that there are some explanatory texts on larger screens.

plurals
  1. POGet value of canvas mustn't return null
    primarykey
    data
    text
    <p>In MainPage.xaml I have 2 canvas controls (bd1 and ball) that represent 2 layers.</p> <pre><code> &lt;Canvas x:Name="ContentCanvas" Width="354" Height="669"&gt; &lt;Canvas.Background&gt; &lt;RadialGradientBrush&gt; &lt;GradientStop Color="#FF9D0A0A" Offset="0" /&gt; &lt;GradientStop Color="Black" Offset="1" /&gt; &lt;/RadialGradientBrush&gt; &lt;/Canvas.Background&gt; &lt;Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="bd1" Width="370" Height="480" Clip="F1 M 0,0L 640,0L 640,480L 0,480L 0,0" MouseMove="Canvas_MouseMove" HorizontalAlignment="Left" VerticalAlignment="Top"&gt; &lt;Canvas.RenderTransform&gt; &lt;TransformGroup&gt; &lt;RotateTransform Angle="0" CenterX="0.5" CenterY="0.5" /&gt; &lt;TranslateTransform X="0" Y="0" /&gt; &lt;ScaleTransform ScaleX="1" ScaleY="1" /&gt; &lt;SkewTransform AngleX="0" AngleY="0"/&gt; &lt;/TransformGroup&gt; &lt;/Canvas.RenderTransform&gt; &lt;Path....../&gt; ........ &lt;/Canvas&gt; &lt;Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="ball" Width="54" Height="52.5" Clip="F1 M 0,0L 54,0L 54,52.5L 0,52.5L 0,0" MouseMove="Canvas_MouseMove" HorizontalAlignment="Left" VerticalAlignment="Top"&gt; &lt;Canvas.RenderTransform&gt; &lt;TransformGroup&gt; &lt;RotateTransform Angle="0" CenterX="0.5" CenterY="0.5" /&gt; &lt;TranslateTransform X="0" Y="0" /&gt; &lt;ScaleTransform ScaleX="1" ScaleY="1" /&gt; &lt;SkewTransform AngleX="0" AngleY="0"/&gt; &lt;/TransformGroup&gt; &lt;/Canvas.RenderTransform&gt; &lt;Canvas Width="640" Height="480.425" Canvas.Left="0" Canvas.Top="0"&gt; &lt;Ellipse x:Name="Ellipse" Width="54" Height="52.5" Canvas.Left="4.17233e-007" Canvas.Top="2.03252e-005" Stretch="Fill" StrokeLineJoin="Round" Stroke="#FFFF0000"&gt; &lt;Ellipse.Fill&gt; &lt;LinearGradientBrush StartPoint="0.0633299,0.762378" EndPoint="0.93667,0.237621"&gt; &lt;LinearGradientBrush.GradientStops&gt; &lt;GradientStop Color="#FF000000" Offset="0"/&gt; &lt;GradientStop Color="#FFFFFFFF" Offset="1"/&gt; &lt;/LinearGradientBrush.GradientStops&gt; &lt;/LinearGradientBrush&gt; &lt;/Ellipse.Fill&gt; &lt;/Ellipse&gt; &lt;/Canvas&gt; &lt;/Canvas&gt; </code></pre> <p>For that I created a class called Layer that has a Canvas property :</p> <pre><code> public class Layer { public Layer() { } public Layer(Canvas canvas, Tipologie tip) { ThisCanvas = canvas; Tip = tip; } public string Name { get; set; } private Canvas canv; public Canvas ThisCanvas { get { return canv; } set { canv = value; if (value != null) Name = value.GetValue(Canvas.NameProperty) as string; } } } </code></pre> <p>In the <code>MainPage</code> class I have a global collection of <code>Layer</code> type. Initially I put in the collection 2 layers.</p> <pre><code> private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e) { Layers[0] = new Layer(); Layers[0].ThisCanvas = GetTemplateChild("bd1") as Canvas; Layers[1] = new Layer(); Layers[1].ThisCanvas = ball; LayerSelector.ItemsSource = Layers; } Layer[] Layers = new Layer[2]; </code></pre> <p>The problem is that bd1 and ball canvas controls are <code>null</code> . I also tried to put the code in the constructor of the page but it was the same problem. </p> <p>I can't explain that. </p> <p>Am I doing something wrong? Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload