Patterns & practices Symposium 2013 Tips for building a Windows Store app using XAML and C#: The Kona project Francis Cheung

Slides:



Advertisements
Similar presentations
MVVM Overview Frank Shoemaker MindCrafted Systems
Advertisements

Windows Phone 7.5 Academic RoadShow Christophe Peerens Neomytic.
Silverlight is dead! Long live MVVM!
Understanding the MVVM pattern
Charles Petzold Application Lifecycle and State Management.
Part 2: Manage app lifecycle and state (Windows Store apps using C#/VB and XAML) us/library/windows/apps/hh aspx
Prism for Windows 8.1 (Building maintainable Windows Store Apps)
MVVM: Filling the Pattern Gap in Silverlight Application Development Bart McDonough Principal Consultant Incline Technical Group.
USING THE MODEL-VIEW- VIEWMODEL PATTERN Laurent Bugnion Director, User Experience Integration IdentityMine
Robert Green | Technical Evangelist Dmitry Lyalin | Product Marketing Manager.
Lessons learned from developing a Windows 8 Metro application in C# Frode Nilsen Nilsen Labs Ticki.
An Introduction to the Model-View-ViewModel Pattern Srsly? Another MV* Pattern? Srsly? Another MV* Pattern?
Dinko Jakovljević Microsoft Student Partner | BambooLab
Essentials of Developing Windows Phone Apps Chinthaka Dissanayake Tech Lead Exilesoft.
WinRT Apps
Microsoft Focus & Expertise We have a world-class team of Microsoft experts that can make any other platform integrate better with an existing enterprise.
Real world Windows Phone development Igor
Charles Petzold Navigation.
MSDN How do I add Voice Commands to my application Find Install Voice Command Sets Search Search for {dictatedSearchTerms} Find Find.
‘Metro’ / Modern – ‘WinRT’ Also known as ‘Windows Store Apps’ --o-0-o-- Windows 8 comes as two parts Win32 and WinRT The Traditional Desktop is Win32 The.
Hot Tuna CROSS PLATFORM DEVELOPMENT WITH.NET, XAMARIN AND MVVMCROSS.
READING, WRITING, BINDING, VALIDATING AND VISUALISING YOUR DATA Business value with Silverlight.
Windows 8 Hot or Not Piotr Włodek. Agenda MetroCharms Contracts WinRT App Execution Environment Motion Summary.
Agenda Windows Phone History WP 7.0 Silverlight WP 7.5 Silverlight WP 8.0 Silverlight WP 8.1 Silverlight WP 8.1 WinRT.
Windows Phone 8 Tips & Tricks for Developers Sascha Corti, Microsoft Switzerland Technical Evangelist | techpreacher.corti.com.
Charles Petzold Launchers and Choosers.
Getting Started with Caliburn.Micro and Windows Phone 7 Gary Ewan Park Twitter: Blog:
Claudio Lassala Software Developer EPS Software / CODE Magazine Session Code: DEV 201.
V 1.0 Programming III. Automatic notifications (…Changed, INofityPropertyChanged, ObservableCollection ) Data formatters Data conversions Resources.
The Windows Runtime (WinRT) is the shared runtime and API space used by store apps across the Windows platform (phone and client) 5 Common WinRT.
Module 12 Attached Properties and Behaviors in WPF.
Windows Phone MVVM and Unit Testing Step by Step Andy Wigley Windows Phone Development MVP, Mobile Software Consultant APPA Mundi Ltd WPH208.
Building State of the art presentation tiers Nauzad Kapadia
Nikhil Kothari Software Architect Microsoft Corporation Session Code: WUX312.
Windows 10 UWP MVVM In Depth
Module 4 Taking Control of the User Interface. Module Overview Sharing Logical Resources in an Application Creating Consistent User Interfaces by Using.
Silverlight 101 Ahead! If you know Silverlight and are looking for more advanced content check out : ‘Microsoft Silverlight “Media” : Moving at 60fps’
Windows Forms in Visual Studio 2005: An in-depth look at key features Name: Joe Stegman Title: Lead Program Manager Session code.
04 |Sharing Code Between Windows 8 and Windows Phone 8 in Visual Studio Ben Riga
V 1.0 Programming III. Automatic notifications with data binding (…Changed, INofityPropertyChanged, ObservableCollection, DataTemplate) Data formatters.
An Introduction to Developing Applications for Microsoft Silverlight Jaime Rodriguez
Integral Users will interact with your app on a big screen with keyboard and mouse.
Model View ViewModel Architecture. MVVM Architecture components.
APLIKACIJE KOJE SU IZVAN SEBE Domagoj Pavlešić, dizzy.hr.
Windows 8 apps and the MVVM pattern SILVERLIGHTSHOW.NET WEBINARS SERIES GILL CLEEREN, October 16 th
Programming with MVVM Miguel A. Castro Architect -
In Windows 8 Store Applications
Real world Windows Phone development
Mobile Development Name Title Company.
Windows Developer Day Fall Creators Update Chris Cortes
Ben Riga 02 | Basics of View Models Ben Riga
TechEd /26/2018 3:42 AM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
Build Windows 10 UWP MVVM Apps with Prism
It’s a Knockout! MVVM Style Web Development
Glenn Block MEF in the real world Glenn Block
11/19/ | App Model & Storage © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered.
Metro style apps using XAML: Make your app shine
Integrating Security Roles into Microsoft Silverlight Applications
An introduction to MVVM using WPF NISCHAL S
Windows Runtime App Lifecycle
04 | UI Presentation & XAML
Page Navigation and Data Binding in Windows Runtime Apps
TechEd /4/2019 3:19 PM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
4/9/ | Contracts © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
XAML Deep Dive for Windows & Windows Phone Apps Jump Start
Bringing existing managed code into Metro style apps
03 | Async Programming & Networking Intro
Tech Ed North America /6/2019 2:07 PM Required Slide
Ch07 生命週期(Life Cycle).
An Introduction to the Model-View-ViewModel Pattern
Presentation transcript:

patterns & practices Symposium 2013 Tips for building a Windows Store app using XAML and C#: The Kona project Francis Cheung

Agenda

Prism for WPF, Silverlight and Windows Phone

The Kona Project

Rethink Prism Scenarios for Windows Store Modularity UI Composition Region Navigation Decoupled Communication Commands MVVM Support

 Walkthrough Demo AdventureWorks Shopper

1. Leverage background in Windows Phone development Windows Phone appsWindows Store apps Deactivate/Tombstoned/ReactivateSuspend/Terminate/Resume Microsoft Push Notification Service (MPN) Windows Push Notification Service (WNS) Windows Phone Marketplace certificationWindows Store app certification & Application Excellence Review (AER) App manifest declares capabilities

2. Focus on AttachedBehaviors No Blend Behavior No BindingExpressions Break out your AttachedBehavior experience and ROCK ON!

3. Push Notification requires Windows Store registration Make sure to register your app with the Windows Store to get proper credentials (SID & secret key) Purely sideloaded apps won’t be able to receive notifications from Windows Notification Service (WNS)

1: async Task AccessTheWebAsync() 2: { 3: HttpClient client = new HttpClient(); 4: Task getStringTask = client.GetStringAsync(" 5: DoIndependentWork(); 6: 7: string urlContents = await getStringTask; 8: return urlContents.Length; 9: } 4. async & await are your friends

Pages and Navigation

Navigation support protected virtual void GoHome(object sender, RoutedEventArgs e) protected virtual void GoBack(object sender, RoutedEventArgs e) protected virtual void GoForward(object sender, RoutedEventArgs e) Visual state switching public void StartLayoutUpdates(object sender, RoutedEventArgs e) public void StopLayoutUpdates(object sender, RoutedEventArgs e) Process lifetime management protected override void OnNavigatedTo(NavigationEventArgs e) protected override void OnNavigatedFrom(NavigationEventArgs e) protected virtual void LoadState(Object navigationParameter, Dictionary pageState) protected virtual void SaveState(Dictionary pageState) 5. Use the LayoutAwarePage class to provide navigation, state management, and visual state management

XAML: Navigation & Visual State Support

protected override void SaveState(System.Collections.Generic.Dictionary pageState) { var virtualizingStackPanel = VisualTreeUtilities.GetVisualChild (itemGridView); if (virtualizingStackPanel != null && pageState != null) { pageState["virtualizingStackPanelHorizontalOffset"] = virtualizingStackPanel.HorizontalOffset; } } protected override void LoadState(object navigationParameter, System.Collections.Generic.Dictionary pageState) { if (pageState != null && pageState.ContainsKey("virtualizingStackPanelHorizontalOffset")) { double.TryParse(pageState["virtualizingStackPanelHorizontalOffset"].ToString(), out virtualizingStackPanelHorizontalOffset); } } LoadState & SaveState: SuspensionManager

Support visual state for landscape, portrait, fill, and snap

World Ready

7. Separate resources for each locale <ToolTip x:Uid=“PreviewCartoonizeAppBarButtonToolTip” Content=“Preview Cartoonization” … />

Model-View-ViewModel Pattern

View First: this.Frame.Navigate(typeof(ItemDetailPage), itemId); ViewModel First: Var itemDetailPageViewModel = new ItemDetailPageViewModel(…) { ItemId = itemId }; navigationService.Navigate(itemDetailPageViewModel); 8. Navigation: View or ViewModel First

Nicki says:

public abstract class BindableBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; protected bool SetProperty (ref T storage, T value, [CallerMemberName] String propertyName = null) { if (object.Equals(storage, value)) return false; storage = value; this.OnPropertyChanged(propertyName); return true; } protected void OnPropertyChanged([CallerMemberName] string propertyName = null) { var eventHandler = this.PropertyChanged; if (eventHandler != null) { eventHandler(this, new PropertyChangedEventArgs(propertyName)); } } } 9. Use BindableBase class to provide INPC

10. Use the Kona ViewModelLocator Convention based lookup MyNamespace.MyPage -> MyNamespace.MyPageViewModel Ability to override convention with exceptions to rule Can leverage container to instantiate ViewModels.

Typical Validation in WPF/Silverlight Implement INotifyDataErrorInfo UI controls bind to errors dictionary if NotifyOnValidationError=True

View: ViewModel: _bindableValidator = new BindableValidator(_address); public BindableValidator Errors { get { return _bindableValidator; } } 11. Use Kona BindableValidator

Decoupled Eventing Hollywood Parent style UI Composition (user control) Child control needs to listen to events raised by long lived services but no way to unhook… Ported Prism EventAggregator

12. Use EventAggregator when necessary public SubscriberViewModel(IEventAggregator eventAggregator) { eventAggregator.GetEvent ().Subscribe(s => UpdateItemCountAsync()); } public PublisherViewModel(IEventAggregator eventAggregator) { _eventAggregator = eventAggregator; } _eventAggregator.GetEvent ().Publish(string.Empty);

Commanding vs ViewModel Method Invocation ICommand: void Execute(object) bool CanExecute(object) event EventHandler CanExecuteChanged Command Invoker: ButtonBase Event -> Action

13. Use DelegateCommand for controls that support ICommand View: ViewModel: ShoppingCartNavigationCommand = new DelegateCommand(NavigateToShoppingCartPage, CanNavigateToShoppingCartPage); ShoppingCartNavigationCommand.RaiseCanExecuteChanged();

14. Use AttachedBehaviors and Actions for the rest View: <GridView x:Name="itemGridView“ ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}" ItemTemplate="{StaticResource KonaRI250x250ItemTemplate}" SelectionMode="None“ IsItemClickEnabled="True" behaviors:ListViewItemClickedToAction.Action= "{Binding CategoryNavigationAction}"> ViewModel: CategoryNavigationAction = NavigateToCategory;

Suspend, Resume, and Terminate

Symposium Use Kona RestorableStateAttribute and MVVM framework public class MyViewModel : ViewModel, INavigationAware { private string _name; [RestorableState] public string Name { get { return _name; } set { SetProperty(ref _name, value); } } }

16. Unit Testing nicely integrated into VS2012 WP7: Jeff Wilcox's Silverlight Unit Test Framework Tests run in emulator or device Unit Test Library (Windows Store apps) Run and debug from IDE Can run tests from command line and export as trx format.

Symposium File System  Local Data (SQLite)  Roaming Data  Hi Priority Roaming Data  Password Vault

Symposium 2013 Thanks!  