Showing posts with label mango. Show all posts
Showing posts with label mango. Show all posts

Wednesday, March 28, 2012

WP7: Isolated Storage

To store app data so that it can be restored when app is tombstoned/deactivated and then restored. stored in key/value pairs


IsolatedStorageSettings setting = IsolatedStorageSettings.ApplicationSettings;
 if (!setting.Contains("rounds")) // check if key exists
 {
     setting.Add("rounds", rounds); // if not, create new key
}
 else
{
      setting["rounds"] = rounds; // if exists, just change the value
}

Reference: http://create.msdn.com/en-US/education/quickstarts/Isolated_Storage

Tuesday, March 27, 2012

WP7: Canvas, Random, 2D Array & Timer



// create a rectangle and fill it with color
Rectangle r = new Rectangle();
 r.Width = r.Height = 50;
r.Fill = new SolidColorBrush(Colors.Orange);
 r.Stroke = new SolidColorBrush(Colors.Black);
 r.StrokeThickness = 3;
// add to canvas
canvas1.Children.Add(r);
// set position

Canvas.SetLeft(r, x);
 Canvas.SetTop(r, y);


// random generator
Random rand = new Random();
int n = rand.Next(maxNumber); // integer :0 to less than maxNumber


// 2D Array
int[,] containers = new int[w, h];

for (int i = 0; i < w; i++ )
 {
       for (int k = 0; k < h; k++)
      {
           containers[i, k] = -1;
       }
 }


// Timer
using System.Windows.Threading;
DispatcherTimer timer = new DispatcherTimer();

timer.Interval = TimeSpan.FromSeconds(5); 
timer.Tick += new EventHandler(timer_Tick);


void timer_Tick(object sender, EventArgs e)
{
     // do something 
 }

Monday, March 26, 2012

WP7: Button MouseDown and Rotate

Interesting that the Button control in silverlight does not support mousedown event.
however, to capture touch down event on the button, has to change the ClickMode of the Button control to "Press" instead of "Release"
and then capture the mousedown event using the "Click" event

Reference: http://www.silverlightshow.net/items/Tip-How-to-handle-the-MouseLeftButtonDown-and-MouseLeftButtonUp-events-of-the-Button-control.aspx

Rotation done using the following:
<Button.RenderTransform>
   <RotateTransform Angle="180" CenterX="100" CenterY="25"/>
</Button.RenderTransform>

Thursday, February 09, 2012

Windows 7 Mango Training - 8-9 Feb

Silverlight, C# in windows 7 phone
Summary of lessons learnt:
  1. same as WPF technology. XAML for layout of UI with CS controlling interactivity and behaviour of app. similar to Flex with MXML and AS 
  2. no Console.Writeline(), have to use System.Diagnostics.Debug.WriteLine()
  3. Loading and Activating events has 10 sec limit. if exceeded OS will terminate app
  4. Loading and Activating event is mutually exclusive
  5. NavigationService.Navigate(Uri) to move from one XAML page to another. eg.: NavigationService.Navigate(new Uri("/IntroPage.xaml", UriKind.RelativeOrAbsolute));
  6. Dormant and Tombstone states
  7. recall x:Name attribute for XAML elements for C# code integration and reference
  8. use Blend to create animation (new StoryBoard, record mode. use timeline) and use Visual Studio to call the animation for interactivity. make sure that XAML file is saved before switching to and fro the 2 tools. file can be overwritten if not careful. 
  9. Easing in blend for a animation segment is set at the end keyframe. eg.: if bounce easing is to be applied between frame 1 and 2, then easing is to be set in frame 2, instead of 1. unlike Flash.
  10. PNG image for App Icon
  11. use System.Windows.Threading.DisptacherTimer to perform timer functions instead of Timer due to access restriction of UI across threads
  12. To change default XAML for a app, change the WMAppManifest.xml in the project to reflect the xaml page in the DefaultTask element.
  13. Touch.FrameReported event (eg.: Touch.FrameReported += new TouchFrameEventHandler(Touch_FrameReported); ) to capture multitouch events on screen. but be careful of the reference point when getting the TouchPoint. Example: TouchPoint pt = e.GetTouchPoints(ContentPanel)[0]; // gets 1st touch with respect to UI Element named "ContentPanel"
  14. for network security access issues when debugging app, may have to run Visual Studio as administrator. right click on "Visual Studio ..." > "Run as administrator"
  15. personal preference: show line numbers. Tool > Options > check "Show all options" > Text Editor > All languages > Display > check "Line numbers"
  16. use WebClient for network HTTP communication
  17. System.Net.Socket supported