Dienstag, 24. August 2010

Windows Phone 7 – Integrate your App in standard picture viewer

With Windows Phone 7 you can integrate your own application seamlessly into the Windows Phone built-in photo viewer. The key to this feature is the Extras.xml file.

You have to place a new xml file with the name Extras.xml to your Windows Phone 7 project root. Set the properties to Copy to Output Directory and select Copy always.

   1: <Extras>
   2:   <PhotosExtrasApplication>
   3:     <Enabled>true</Enabled>
   4:     <StorageFolder>Incoming</StorageFolder>
   5:   </PhotosExtrasApplication>
   6: </Extras>

For the StorageFolder attribute you can choose your own name.

More informations you could find here: How to: Create a Photo Extras Application for Windows Phone

Sonntag, 22. August 2010

Windows Phone 7: Virtualization of the List control

One fantastic feature of Silverlight is that you can "virtualize" the UI objects needed to render a list, reducing the amount of memory and CPU necessary to load large lists. So you can bind a ListBox to 1.000.000 items, but you create only ListBoxItems for the first 100 items. This helps you to make your Windows Phone 7 App a little bit quicker if you want to work with large data lists.

The only thing you have to do is to derive your data source from IList. This fact triggers Silverlight to do data virtualization.

More informations about this feature you can found at Peter Torr’s Blog:

Virtualizing Data in Windows Phone 7 Silverlight Applications - Peter Torr's Blog - Site Home - MSDN Blogs

Samstag, 14. August 2010

High performance apps for Windows Phone 7

Here you could some very good tips to build high performace apps for Windows Phone 7 with Silverlight.

At compiledexperience.com they have a lot of new samples of Windows Phone 7 applications.

Dienstag, 10. August 2010

Windows Phone 7 – Emulator keyboard shortcuts

The Windows Phone 7 emulator has a number of shortcut keys that are good to know about:

The hardware keyboard can be toggled by pressing the Pause key, or opened / closed via the Page Up / Page Down key. The hardware keyboard closes the software one, so you can only use on at a time. When the hardware keyboard is open, a little icon is displayed on the top of the screen:

F1 on the keyboard equals to pressing the back button on the phone.

Pressing the F2 or the Windows key while the emulator has focus acts as if the phone’s Windows key was pressed. Continuously pressing it for a while brings up the voice command / search interface.

F3 works as the third physical button on the phone, bring up the Bing search.

F7 is wired to the physical camera button.

F9 and F10 raise and lower the volume. Pressing these brings up an interesting piece of UI, for controlling the currently playing music or radio, and switching the phone to vibrate.

F11 acts as the play / pause button. It is interesting that such a button is in the emulator as this button is not a required hardware button for Windows Phone 7 (WP7).

Freitag, 30. Juli 2010

Silverlight: Set Focus to selected item in Listbox

If you want to set the focus to the selected item in your Silverlight Listbox Control you have to use this dirty trick:

   1: int selectedIndex = itemsListBox.SelectedIndex;
   2:                itemsListBox.SelectedIndex = 0;
   3:                itemsListBox.Focus();
   4:                itemsListBox.SelectedIndex = selectedIndex;

Silverlight: DataGrid and Comboxbox with MVVM

If you are using a MVVM pattern with a view model you have generally the problem to bind a combobox inside a Datagrid because you cannot access the data context of your view by referencing with the elementname syntax. The trick to bind your Comboxbox inside a DataGridTemplateColumn is to define the reference to your viewmodel with a StaticResoucre and use this for the DataContext-Binding and combobox-Binding:

StaticResoucre of the viewmodel
   1:  
   2:     <controls:ChildWindow.Resources>
   3:         <ViewModels:SettingsViewModel x:Key="SettingsViewModel" />
   4:     </controls:ChildWindow.Resources>
Binding the view to your viewmodel
   1: <Grid x:Name="LayoutRoot" Margin="2" DataContext="{StaticResource SettingsViewModel}">
Combobox-Binding in the Datagrid
   1: <sdk:DataGridTemplateColumn.CellEditingTemplate>
   2:     <DataTemplate>
   3:         <ComboBox ItemsSource="{Binding Gesellschaften,Source={StaticResource SettingsViewModel}}" 
   4:                   DisplayMemberPath="Name" SelectedValue="{Binding GesellschaftId, Mode=TwoWay}" 
   5:                   SelectedValuePath="GesellschaftId"  />
   6:     </DataTemplate>
   7: </sdk:DataGridTemplateColumn.CellEditingTemplate>

Samstag, 17. Juli 2010

Silverlight: Drag & Drop Timing problems

If you use the new Silverlight 4 controls for drag&drop you have sometimes the problem that in your control the drag Event started even if you only select the next item in your listbox or treeview. The reason for this is that you maybe have long running events at your SelectedItem-Events. This forces the Drag&Drop-Container to raise a DragEnter-Event because the control does not become the MouseUp-Event in the desired time.

To solve this problem we made in our current project several approaches (Background process etc.). But the best way to reach your goal is a very “oldschool” method:

Using a timer to make your long running events  in the SelectedItem-Event

On SelectedItem Changed:
   1: var selectedEntryChangedTimer =
   2:                     new DispatcherTimer
   3:                         {
   4:                             Interval =
   5:                                 new TimeSpan(0, 0, 0, 0,
   6:                                             250)
   7:                         };
   8:                 selectedEntryChangedTimer.Tick += OnSelectedEntryChangedTimer;
   9:                 selectedEntryChangedTimer.Start();
 
Eventhandler:
   1: private void OnSelectedEntryChangedTimer(object o, EventArgs args)
   2: {
   3:     var timer = (DispatcherTimer)o;
   4:     timer.Stop();
   5:  
   6:     EventBroker.GetEvent<SelectedBilanzObjektChangedEvent>().Publish(
   7:         new SelectedBilanzObjektChangedEventArgs(_selectedEntry));
   8: }