Your SlideShare is downloading. ×
Windows Store app using XAML and C#: Enterprise Product Development
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

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

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide
  • Line of Business emphasis…
  • ExplainSideLoaded
  • Don’t need command enablement….
  • Transcript

    • 1. Windows Store app using XAML andC#: Enterprise Product DevelopmentWhat beyond POCs ?! Mahmoud Hamed ITWorxpatterns & practices Symposium 2013
    • 2. Mahmoud @mhamedmahmoudHamed moudhamedmahmoud
    • 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. Why I need this session can I livewithout it ??????!patterns & practices Symposium 2013
    • 5. Agenda 
    • 6. The Kona Project
    • 7. Demo Kona Project
    • 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. Demo TFS 2012 and Windows StoreApps
    • 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. 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. Globalization <ToolTip x:Uid=“PreviewCartoonizeAppBarButtonToolTip” Content=“Preview Cartoonization” … />
    • 13. GlobalizationA. Globalizing your app How to use the Multilingual App Toolkit Application resources and localization sample
    • 14. Demo Windows Store AppsGlobalization
    • 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. Demo Windows Store Apps Logging
    • 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. Model-View-ViewModel Pattern
    • 19. From MVC to MVVM DataBinding Commands Services Messages Events
    • 20. ViewModel  View Behaviour BindingLoose coupling, more flexibilityBehavior is highly Blendable
    • 21. ViewModel  View (Win8)No behaviors in Windows 8 Workaround: Use properties and binding PropertyChanged event Binding PropertyChanged
    • 22. Focus on AttachedBehaviors• No Blend Behavior<T>• No BindingExpressions• Break out your AttachedBehavior experience and ROCK ON!
    • 23. View services ISelectFilesService injection
    • 24. MVVM Light
    • 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. Commanding vs ViewModel MethodInvocationICommand: void Execute(object) bool CanExecute(object) event EventHandler CanExecuteChangedCommand Invoker: ButtonBase-----------------------------------------------------Event -> Action
    • 27. Use DelegateCommand for controls thatsupport ICommandView:<Button Content=“Go to shopping cart” Command="{Binding ShoppingCartNavigationCommand}" />ViewModel:ShoppingCartNavigationCommand = newDelegateCommand(NavigateToShoppingCartPage, CanNavigateToShoppingCartPage);ShoppingCartNavigationCommand.RaiseCanExecuteChanged();
    • 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. Use the Kona ViewModelLocator• Convention based lookup• Ability to override convention with exceptions to rule• Can leverage container to instantiate ViewModels.
    • 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. 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. Navigation: View or ViewModel FirstView First:this.Frame.Navigate(typeof(ItemDetailPage), itemId);ViewModel First:Var itemDetailPageViewModel = new ItemDetailPageViewModel(…) { ItemId = itemId };navigationService.Navigate(itemDetailPageViewModel);
    • 33. Pages and Navigation
    • 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. Navigation & Visual State SupportXAML:<Button Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/><UserControl Loaded="StartLayoutUpdates" Unloaded="StopLayoutUpdates">
    • 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. 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. 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. 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. Suspend, Resume, and Terminate
    • 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. 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. File System Local Data (SQLite) Roaming Data Hi Priority Roaming Data Password Vault Symposium 2013
    • 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. Thanks! Symposium 2013