473,387 Members | 1,344 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

WP7: Canvas controls from xaml can be null?

In MainPage.xaml I have 2 canvas controls (bd1 and ball) that represent 2 layers.
Expand|Select|Wrap|Line Numbers
  1. <Canvas  x:Name="ContentCanvas" Width="354" Height="669">
  2.                 <Canvas.Background>
  3.                         <RadialGradientBrush>
  4.                             <GradientStop Color="#FF9D0A0A" Offset="0" />
  5.                             <GradientStop Color="Black" Offset="1" />
  6.                         </RadialGradientBrush>
  7.                 </Canvas.Background>
  8.                 <Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  9.                             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  10.                             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">
  11.                         <Canvas.RenderTransform>
  12.                             <TransformGroup>
  13.                                 <RotateTransform Angle="0" CenterX="0.5" CenterY="0.5" />
  14.                                 <TranslateTransform X="0" Y="0" />
  15.                                 <ScaleTransform ScaleX="1" ScaleY="1" />
  16.                                 <SkewTransform AngleX="0" AngleY="0"/>
  17.                             </TransformGroup>
  18.                         </Canvas.RenderTransform>
  19.                         <Path....../>
  20.                         ........
  21.                 </Canvas>
  22.                 <Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  23.                             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="ball" 
  24.                             Width="54" Height="52.5" Clip="F1 M 0,0L 54,0L 54,52.5L 0,52.5L 0,0"
  25.                              MouseMove="Canvas_MouseMove" HorizontalAlignment="Left" VerticalAlignment="Top">
  26.                         <Canvas.RenderTransform>
  27.                             <TransformGroup>
  28.                                 <RotateTransform Angle="0" CenterX="0.5" CenterY="0.5" />
  29.                                 <TranslateTransform X="0" Y="0" />
  30.                                 <ScaleTransform ScaleX="1" ScaleY="1" />
  31.                                 <SkewTransform AngleX="0" AngleY="0"/>
  32.                             </TransformGroup>
  33.                         </Canvas.RenderTransform>
  34.                         <Canvas Width="640" Height="480.425" Canvas.Left="0" Canvas.Top="0">
  35.                             <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">
  36.                                 <Ellipse.Fill>
  37.                                     <LinearGradientBrush StartPoint="0.0633299,0.762378" EndPoint="0.93667,0.237621">
  38.                                         <LinearGradientBrush.GradientStops>
  39.                                             <GradientStop Color="#FF000000" Offset="0"/>
  40.                                             <GradientStop Color="#FFFFFFFF" Offset="1"/>
  41.                                         </LinearGradientBrush.GradientStops>
  42.                                     </LinearGradientBrush>
  43.                                 </Ellipse.Fill>
  44.                             </Ellipse>
  45.                         </Canvas>
  46.                     </Canvas>
For that I created a class called Layer that has a Canvas property :

Expand|Select|Wrap|Line Numbers
  1. public class Layer
  2.         {
  3.                 public Layer() { }
  4.                 public Layer(Canvas canvas, Tipologie tip) 
  5.                 {
  6.                     ThisCanvas = canvas; Tip = tip;
  7.                 }
  8.                 public string Name { get; set; }  
  9.                 private Canvas canv;
  10.                 public Canvas ThisCanvas
  11.                 {
  12.                     get { return canv; }
  13.                     set
  14.                     {                
  15.                         canv = value;
  16.                         if (value != null)                        
  17.                             Name = value.GetValue(Canvas.NameProperty) as string;
  18.                     }
  19.                 }
  20.         }

In the MainPage class I have a global collection of Layer type. Initially I put in the collection 2 layers.

Expand|Select|Wrap|Line Numbers
  1. private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
  2.         {
  3.             Layers[0] = new Layer(); Layers[0].ThisCanvas = GetTemplateChild("bd1") as Canvas;
  4.             Layers[1] = new Layer(); Layers[1].ThisCanvas = ball;
  5.             LayerSelector.ItemsSource = Layers;
  6.         } 
  7.         Layer[] Layers = new Layer[2];
The problem is that bd1 and ball canvas controls are null . I also tried to put the code in the constructor of the page but it was the same problem.

I can't explain that.

Am I doing something wrong? Thanks in advance!
Feb 7 '12 #1
0 1408

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: headware | last post by:
I have a user control that is basically a Datagrid with a few additional controls for filtering the data and showing/hiding columns. I'd like to be able to reuse this control in different places...
1
by: Randall Parker | last post by:
In places where ASP.Net does the handling of controls for you does it treat controls as null or as zero length strings?
12
by: AricC | last post by:
Currently I am manually setting each control on my form to null to reset. Does anyone know how to do this with a loop or a more simple command? I've seen some make shift control arrays but none...
2
by: kalaivanan | last post by:
hi, i am trying to add a datagrid control to a web page dynamically. i am able to do it while i used the following code in the page load event of the form in which i am going to add the control. ...
26
by: Jon Davis | last post by:
OK, why is Canvas not IDisposable, and how do I get rid of all the Windows handles? I'm doing a performance test of looping through a dynamic XAML-to-JPEG conversion. It gets to about 500...
2
by: germ | last post by:
I am moving a web application from 1.1 to 2.0 This site builds pages dynamically as : PlaceHolder.Controls.Add(LoadControl("~/Controls/Ctl1.ascx")); Everything is working fine as long as the web...
2
by: =?Utf-8?B?a2V2aW4=?= | last post by:
using VS2005 My masterpage has two panels and two hyperlinks. The initial content aspx page is blank. The page_load event of the masterpage hides one of the panels based on SESSION...
12
by: binky | last post by:
Quick question that I can't find a solution to: I have an ADP application that uses SQL Server 2000 backend, along with stored procedures that populate my forms. I do not want to use subforms for...
6
ilya Kraft
by: ilya Kraft | last post by:
Hello, i found this cool HTML5 feature called Gradient canvas. I would like to use it as a website background, is it possible to somehow place content on it? when i use divs and table nothing appears...
5
ilya Kraft
by: ilya Kraft | last post by:
Hello I have this interactive canvas as a background of my web, it is on 100% width and high, but when I add content that continues longer than canvas and you have to scroll down, canvas is not...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.