Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 1st, 2012  |  syntax: None  |  size: 1.39 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Creating Canvas dynamically
  2. public MainPage()
  3.     {
  4.         InitializeComponent();
  5.  
  6.         int size = 50;
  7.         Canvas myCanvas = new Canvas();
  8.         Canvas.SetLeft(myCanvas, 0);
  9.         myCanvas.Width = size;
  10.  
  11.         Color c = new Color();
  12.         c.R = 255;
  13.         c.B = 0;
  14.         c.G = 255;
  15.  
  16.         myCanvas.Background = new SolidColorBrush(c);
  17.  
  18.         ContentPanel.Height = 100;
  19.         ContentPanel.Width = 100;
  20.         ContentPanel.Children.Add(myCanvas);
  21.         ApplicationTitle.Text = ContentPanel.ActualHeight.ToString();
  22.  
  23.     }
  24.        
  25. <Grid x:Name="LayoutRoot" Background="Transparent">
  26.     <Grid.RowDefinitions>
  27.         <RowDefinition Height="Auto"/>
  28.         <RowDefinition Height="*"/>
  29.     </Grid.RowDefinitions>
  30.  
  31.     <!--TitlePanel contains the name of the application and page title-->
  32.     <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
  33.         <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
  34.         <TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
  35.     </StackPanel>
  36.  
  37.     <!--ContentPanel - place additional content here-->
  38.     <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
  39.  
  40.     </Grid>
  41. </Grid>
  42.        
  43. Color c = new Color();
  44.     c.R = 255;
  45.     c.B = 0;
  46.     c.G = 255;
  47.  
  48.     c.A = 255;  // this is what you need to add to make it visible.