Tuesday, December 28, 2010
Getting MVVM Light to work with WP7
I ran into several issues while getting MVVM Light V3 (http://www.galasoft.ch/mvvm/installing/manually/) to work with VS 2010 ver 10.0.30319.1 and the first Release version of WP7 Tools.
The major difference is the Navigation namespace is now inside the Microsoft.Phone.Controls namespace.
Following are the steps I took to add an MVVM Light WP7 project to run.
Changes to Project References
Add reference to
Microsoft.Phone
Microsoft.Phone.Interop
remove refrence to
Microsoft.Phone.Controls.Navigation
Changes to WMAppManifest.xml
the "L" in silverlight is no longer a capital letter, Change case of RuntimeType value to
Silverlight
remove instance of
PlaceHolderString="Default task"
Changes to Permissions on .dll's
Error messages may pop up saying .dll's are flagged from being downloaded from the web.
-Navigate to the files in explore
-right click an offending file
-select properties
-on the "General" tab click "Unblock" near the bottom.
Changes to App.xaml
remove from App.xaml
xmlns:phoneNavigation="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Navigation"
and
Source="/MainPage.xaml" />
Add to App.xaml.cs
the usings
using Microsoft.Phone.Controls;
using System.Windows.Navigation;
and
Changes to MainPage.xaml
remove
xmlns:phoneNavigation="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Navigation"
add
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
change phoneNavigation:PhoneApplicationPage to phone:PhoneApplicationPage on both the top of the page and the bottom
Edit: This didn't fix everything, there are issues such as the ListViewItem being replaced by the ListBoxItem. I recommend following the link Laurent Bugnion commented below, where he's already done all the work for us. If you're really curious of all the changes do a diff between the templates.
The major difference is the Navigation namespace is now inside the Microsoft.Phone.Controls namespace.
Following are the steps I took to add an MVVM Light WP7 project to run.
Changes to Project References
Add reference to
Microsoft.Phone
Microsoft.Phone.Interop
remove refrence to
Microsoft.Phone.Controls.Navigation
Changes to WMAppManifest.xml
the "L" in silverlight is no longer a capital letter, Change case of RuntimeType value to
Silverlight
remove instance of
PlaceHolderString="Default task"
Changes to Permissions on .dll's
Error messages may pop up saying .dll's are flagged from being downloaded from the web.
-Navigate to the files in explore
-right click an offending file
-select properties
-on the "General" tab click "Unblock" near the bottom.
Changes to App.xaml
remove from App.xaml
xmlns:phoneNavigation="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Navigation"
and
Add to App.xaml.cs
the usings
using Microsoft.Phone.Controls;
using System.Windows.Navigation;
and
public App()
{
...keep code already in there and add lines below
// Phone-specific initialization
InitializePhoneApplication();
}
#region Phone application initialization
///
/// Provides easy access to the root frame of the Phone Application.
///
///The root frame of the Phone Application.
public PhoneApplicationFrame RootFrame { get; private set; }
// Avoid double-initialization
private bool phoneApplicationInitialized = false;
// Do not add any additional code to this method
private void InitializePhoneApplication()
{
if (phoneApplicationInitialized)
return;
// Create the frame but don't set it as RootVisual yet; this allows the splash
// screen to remain active until the application is ready to render.
RootFrame = new PhoneApplicationFrame();
RootFrame.Navigated += CompleteInitializePhoneApplication;
// Handle navigation failures
RootFrame.NavigationFailed += RootFrame_NavigationFailed;
// Ensure we don't initialize again
phoneApplicationInitialized = true;
}
// Do not add any additional code to this method
private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e)
{
// Set the root visual to allow the application to render
if (RootVisual != RootFrame)
RootVisual = RootFrame;
// Remove this handler since it is no longer needed
RootFrame.Navigated -= CompleteInitializePhoneApplication;
}
// Code to execute if a navigation fails
private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached)
{
// A navigation has failed; break into the debugger
System.Diagnostics.Debugger.Break();
}
}
#endregion
Changes to MainPage.xaml
remove
xmlns:phoneNavigation="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Navigation"
add
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
change phoneNavigation:PhoneApplicationPage to phone:PhoneApplicationPage on both the top of the page and the bottom
Edit: This didn't fix everything, there are issues such as the ListViewItem being replaced by the ListBoxItem. I recommend following the link Laurent Bugnion commented below, where he's already done all the work for us. If you're really curious of all the changes do a diff between the templates.
Labels: MVVM Light, MVVM Light V3, WP7
Comments:
<< Home
Hi,
There is a hotfix for WP7 tools RTM, available at http://blog.galasoft.ch/archive/2010/07/22/mvvm-light-hotfix-for-windows-phone-7-developer-tools-beta.aspx
Cheers,
Laurent
Post a Comment
There is a hotfix for WP7 tools RTM, available at http://blog.galasoft.ch/archive/2010/07/22/mvvm-light-hotfix-for-windows-phone-7-developer-tools-beta.aspx
Cheers,
Laurent
Subscribe to Post Comments [Atom]
<< Home
Subscribe to Posts [Atom]