Windows Store app using XAML and C#: Enterprise Product Development


Published on

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • Line of Business emphasis…
  • ExplainSideLoaded
  • Don’t need command enablement….
  • Windows Store app using XAML and C#: Enterprise Product Development

    1. 1. Windows Store app using XAML andC#: Enterprise Product DevelopmentWhat beyond POCs ?! Mahmoud Hamed ITWorxpatterns & practices Symposium 2013
    2. 2. Mahmoud @mhamedmahmoudHamed moudhamedmahmoud
    3. 3. This presentation is based on a presentationby p&p team at pattern & practicessymposium 2013 with updates to reflect myown experienceTips for building a Windows Store app usingXAML and C#: The Kona projectpatterns & practices Symposium 2013
    4. 4. Why I need this session can I livewithout it ??????!patterns & practices Symposium 2013
    5. 5. Agenda 
    6. 6. The Kona Project
    7. 7. Demo Kona Project
    8. 8. Build and Test a Windows Store App Using TeamFoundation BuildA. Build Windows Store App Using Team Foundation Build Walkthrough: Creating and Running Unit Tests for Windows Store Apps Validating an app package in automated builds (Windows Store apps)Windows Store app certification TFS 2012 Express (5 user per server)
    9. 9. Demo TFS 2012 and Windows StoreApps
    10. 10. Windows Phone vs Windows Store app Windows Phone apps Windows Store apps Deactivate/Tombstoned/Reactivate Suspend/Terminate/Resume Microsoft Push Notification Service Windows Push Notification Service (MPN) (WNS) Windows Phone Marketplace certification Windows Store app certification & Application Excellence Review (AER) App manifest declares capabilities App manifest declares capabilities
    11. 11. 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)
    12. 12. Globalization <ToolTip x:Uid=“PreviewCartoonizeAppBarButtonToolTip” Content=“Preview Cartoonization” … />
    13. 13. GlobalizationA. Globalizing your app How to use the Multilingual App Toolkit Application resources and localization sample
    14. 14. Demo Windows Store AppsGlobalization
    15. 15. LoggingLogging Sample for Windows Store Apps (ETW Logging in WinRT) OverviewMetroLog is a lightweight logging framework designed for Windows Storeand Windows Phone 8 apps
    16. 16. Demo Windows Store Apps Logging
    17. 17. async & await are your friends1: async Task<int> AccessTheWebAsync()2: {3: HttpClient client = new HttpClient();4: Task<string> getStringTask = client.GetStringAsync("");5: DoIndependentWork();6:7: string urlContents = await getStringTask;8: return urlContents.Length;9: }
    18. 18. Model-View-ViewModel Pattern
    19. 19. From MVC to MVVM DataBinding Commands Services Messages Events
    20. 20. ViewModel  View Behaviour BindingLoose coupling, more flexibilityBehavior is highly Blendable
    21. 21. ViewModel  View (Win8)No behaviors in Windows 8 Workaround: Use properties and binding PropertyChanged event Binding PropertyChanged
    22. 22. Focus on AttachedBehaviors• No Blend Behavior<T>• No BindingExpressions• Break out your AttachedBehavior experience and ROCK ON!
    23. 23. View services ISelectFilesService injection
    24. 24. MVVM Light
    25. 25. Use BindableBase class to provideINPCpublic abstract class BindableBase : INotifyPropertyChanged{ public event PropertyChangedEventHandler PropertyChanged; protected bool SetProperty<T>(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)); } }}
    26. 26. Commanding vs ViewModel MethodInvocationICommand: void Execute(object) bool CanExecute(object) event EventHandler CanExecuteChangedCommand Invoker: ButtonBase-----------------------------------------------------Event -> Action
    27. 27. Use DelegateCommand for controls thatsupport ICommandView:<Button Content=“Go to shopping cart” Command="{Binding ShoppingCartNavigationCommand}" />ViewModel:ShoppingCartNavigationCommand = newDelegateCommand(NavigateToShoppingCartPage, CanNavigateToShoppingCartPage);ShoppingCartNavigationCommand.RaiseCanExecuteChanged();
    28. 28. Use AttachedBehaviors and Actions forthe restView:<GridView x:Name="itemGridView“ ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}" ItemTemplate="{StaticResource KonaRI250x250ItemTemplate}" SelectionMode="None“ IsItemClickEnabled="True" behaviors:ListViewItemClickedToAction.Action= "{Binding CategoryNavigationAction}">ViewModel:CategoryNavigationAction = NavigateToCategory;
    29. 29. Use the Kona ViewModelLocator• Convention based lookup• Ability to override convention with exceptions to rule• Can leverage container to instantiate ViewModels.
    30. 30. 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
    31. 31. Use EventAggregator whennecessarypublic SubscriberViewModel(IEventAggregator eventAggregator){ eventAggregator.GetEvent<ShoppingCartUpdatedEvent>() .Subscribe(s => UpdateItemCountAsync());}public PublisherViewModel(IEventAggregator eventAggregator){ _eventAggregator = eventAggregator;}_eventAggregator.GetEvent<ShoppingCartUpdatedEvent>() .Publish(string.Empty);
    32. 32. Navigation: View or ViewModel FirstView First:this.Frame.Navigate(typeof(ItemDetailPage), itemId);ViewModel First:Var itemDetailPageViewModel = new ItemDetailPageViewModel(…) { ItemId = itemId };navigationService.Navigate(itemDetailPageViewModel);
    33. 33. Pages and Navigation
    34. 34. Use the LayoutAwarePage class to provide navigation, state management, and visual state managementNavigation 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<String, Object> pageState) protected virtual void SaveState(Dictionary<String, Object> pageState)
    35. 35. Navigation & Visual State SupportXAML:<Button Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/><UserControl Loaded="StartLayoutUpdates" Unloaded="StopLayoutUpdates">
    36. 36. LoadState & SaveState: SuspensionManagerprotected override void SaveState(System.Collections.Generic.Dictionary<string, object> pageState){ var virtualizingStackPanel = VisualTreeUtilities.GetVisualChild<VirtualizingStackPanel>(itemGridView); if (virtualizingStackPanel != null && pageState != null) { pageState["virtualizingStackPanelHorizontalOffset"] = virtualizingStackPanel.HorizontalOffset; }}protected override void LoadState(object navigationParameter, System.Collections.Generic.Dictionary<string, object> pageState){ if (pageState != null && pageState.ContainsKey("virtualizingStackPanelHorizontalOffset")) { double.TryParse(pageState["virtualizingStackPanelHorizontalOffset"].ToString(), out virtualizingStackPanelHorizontalOffset); }}
    37. 37. Support visual state for landscape, portrait, fill, andsnap<VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="ApplicationViewStates"> <VisualState x:Name="FullScreenLandscape"/> <VisualState x:Name="Filled"/> <VisualState x:Name="FullScreenPortrait"> <Storyboard> ... </Storyboard> </VisualState> <VisualState x:Name="Snapped"> <Storyboard> ... </Storyboard> </VisualState> </VisualStateGroup></VisualStateManager.VisualStateGroups>
    38. 38. Typical Validation in WPF/Silverlight• Implement INotifyDataErrorInfo• UI controls bind to errors dictionary if NotifyOnValidationError=True<TextBox Text="{Binding Id, Mode=TwoWay, ValidatesOnExceptions=True,NotifyOnValidationError=True}"/>
    39. 39. Use Kona BindableValidatorView:<TextBox Text="{Binding Address.FirstName, Mode=TwoWay}" behaviors:HighlightFormFieldOnErrors.PropertyErrors="{BindingErrors[FirstName]}" />ViewModel:_bindableValidator = new BindableValidator(_address);public BindableValidator Errors{ get { return _bindableValidator; }}
    40. 40. Suspend, Resume, and Terminate
    41. 41. 15. Use Kona RestorableStateAttribute and MVVMframeworkpublic class MyViewModel : ViewModel, INavigationAware{ private string _name; [RestorableState] public string Name { get { return _name; } set { SetProperty(ref _name, value); } }} Symposium 2013
    42. 42. Unit Testing nicely integrated into VS2012WP7: Jeff Wilcoxs Silverlight Unit Test Framework• Tests run in emulator or deviceUnit Test Library (Windows Store apps)• Run and debug from IDE• Can run tests from command line and export as trx format.<ItemGroup> <TestAppPackages Include="$(MSBuildProjectDirectory)..Source***.appx" /></ItemGroup><Target Name="Test"> <Exec ContinueOnError="true" Command="vstest.console.exe /InIsolation /logger:trx%(TestAppPackages.Identity)" /></Target>
    43. 43. File System Local Data (SQLite) Roaming Data Hi Priority Roaming Data Password Vault Symposium 2013
    44. 44. Final Tips Read Windows 8 SDK  Watch Some videos  Channel 9: Windows Camps   Channel 9: Windows tag   Pluralsight windows 8 series  Symposium 2013
    45. 45. Thanks! Symposium 2013