473,799 Members | 3,107 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

WP7: Canvas controls from xaml can be null?

1 New Member
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 1426

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

Similar topics

0
1096
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 throughout my code but allow it to work with different tables in the database. I thought that I would use the Template pattern to achieve this. I put all the functions in an abstract base class which inherited from UserControl except a...
1
1060
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
16026
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 that would work for me. Thanks, Aric
2
2318
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. DataGrid dG = new DataGrid(); Control frm = FindControl("frmSnAInformation"); frm.Controls.Add(dG); DataSet ds = nam_Db.dbFunctions.funFetchDataSet("fetchSuInfo_all"); dG.DataSource = ds.Tables;
26
3601
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 conversions and then crashes. Task Manager says that about 6000 Windows handles were created and the count never decrements. My code (loop not shown):
2
1943
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 site is updateable - the .ascx files exist on disk. I would like to use the non-updateable and single assembly options - no ..ascx files. I thought that maybe this would work :...
2
3733
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 variables. When I press one particular link all controls are null, thus throwing an error. The other hyperlink behaves normally.
12
3146
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 various reasons, so my data is loaded into a single form (record source is a stored procedure, and the form's InputParameters are changed depending on the data to load, pretty standard). However, if no records are returned by the procedure, all...
6
2433
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 only this canvas. Here is a file i want to use as a background. <!DOCTYPE html> <html lang="en"><head> <meta charset="utf-8"> <title>ilya daderko</title> <style>
5
2881
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 repeating down y axis. Also can anyone tell how can i center align absolute positioned <div>. I added white box that is longer than canvas, if you scroll down you start to see black background, how can I make canvas repeat down y-axis and how do i...
0
9687
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9541
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10485
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9073
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7565
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.