Aug 25, 2011

Using WP7 Profiler

Windows Phone 7 SDK RC add exciting new feature to developers. After installed new developer tools I noticed Microsoft Windows Phone 7.1 Profiler in About menu of Visual studio 2010 for Windows Phone. Quick Googling give no results, but everything more easy than can looks.

Open Your WP7 project and look into Debug menu. You will see disabled (probably not) menu item Start Windows Phone Performance Analysis

To enable this item You have to switch Your project target from Windows Phone 7.0 to 7.1 in Project -> Properties menu. So if Your application targeted current market, you have to make project clone prior profiling, cause You cannot switch back to 7.0.

When application targeted Mango You can open profiler. Choose options and click hyperlink Launch Application.

After working with application click Stop Profiling. After analysis You will see profiling results. Select timeline and it shows details.

Update: Finally found MSDN Page, describing WP7 Profiler

No more using of MSAF for WP7 Analytics

While looking for analytics for my WP7 application, i've found MSAF - Microsoft Silverlight Analytics Framework.

Project looks great, but first i figured out is have many assemblies and dependencies.

Making test application is almost impossible - lack of clear documentation. Samples also unclear and possible i never tried this framework, but fortunately i've found kodirer blog. Thanks to Mr. Rene - he has clearly described neccessary steps to work it out.

Sample app with simple static page works well, but when i add it to my panorama application i saw Crippling Performance Issue. Issue ticket contains attached "fixed" assembly, which is make issue not so sharp, but still noticable performance decrease.

I found years ago, that some MS Frameworks, written on best pattern practices is buggy and performance killers.

Only thing is needed is to call Google Analytics site once in application, so why it need to intrude in any kind of events in application. Even if will fixed for this particular issue i cannot be sure about all other cases.

So, it's time to write my own analytics tracker...

Aug 6, 2011

Handle OnClick Event in ListBox on Silverlight for Windows Phone 7

Generally on Windows Phone 7 using Silverlight You will use ListBox templates like this one

  1. <ListBox Margin="0,0,-12,0" ItemsSource="{Binding Items}" >  
  2.     <ListBox.ItemTemplate>  
  3.         <DataTemplate>  
  4.             <StackPanel Orientation="Horizontal" Margin="0,0,0,17"  
  5.                        MouseLeftButtonDown="StackPanel_MouseLeftButtonDown">  
  6.                 <Image Height="150" Width="150" Source="{Binding ImageSource}" Stretch="UniformToFill" />  
  7.                 <StackPanel Width="311">  
  8.                     <TextBlock Text="{Binding LineOne}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>  
  9.                     <TextBlock Text="{Binding LineTwo}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>  
  10.                 </StackPanel>  
  11.             </StackPanel>  
  12.         </DataTemplate>  
  13.     </ListBox.ItemTemplate>  
  14. </ListBox>  

But on touch based platform such as Windows Phone 7, MouseLeftButtonDown will trigger event, even if You try scroll ListBox content. Another aproach is to use ManipulationCompleted event. Event arguments have property named IsTapEvent, but in latest Silverlight SDK this property is declared as Protected. So You can see it in debugger at runtime, but cannot use in code.

What You can do is subscribe to ManipulationCompleted event, and check e.TotalManipulation for Scale and Transform properties equals zero.

  1. private void StackPanel_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)    
  2. {    
  3.     var zero = new Point(0,0);    
  4.     if( e.TotalManipulation.Scale == zero && e.TotalManipulation.Translation == zero )    
  5.         MessageBox.Show("gotcha!");    
  6. }