• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Windows Store app using XAML and C#: Enterprise Product Development
 

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

on

  • 2,472 views

 

Statistics

Views

Total Views
2,472
Views on SlideShare
2,465
Embed Views
7

Actions

Likes
2
Downloads
0
Comments
0

2 Embeds 7

http://www.linkedin.com 5
https://twitter.com 2

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Line of Business emphasis…
  • ExplainSideLoaded
  • Don’t need command enablement….

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

  • Windows Store app using XAML andC#: Enterprise Product DevelopmentWhat beyond POCs ?! Mahmoud Hamed ITWorxpatterns & practices Symposium 2013
  • Mahmoud mahmoud.hamed@itworx.com @mhamedmahmoudHamed http://eg.linkedin.com/in/mah dev.mhamed@gmail.com moudhamedmahmoud
  • 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
  • Why I need this session can I livewithout it ??????!patterns & practices Symposium 2013
  • Agenda 
  • The Kona Project
  • Demo Kona Project
  • Build and Test a Windows Store App Using TeamFoundation BuildA. Build Windows Store App Using Team Foundation Buildhttp://msdn.microsoft.com/en-us/library/hh691189.aspxB. Walkthrough: Creating and Running Unit Tests for Windows Store Appshttp://msdn.microsoft.com/en-us/library/hh440545.aspxC. Validating an app package in automated builds (Windows Store apps)Windows Store app certificationhttp://msdn.microsoft.com/en-us/library/windows/apps/hh994667.aspxD. TFS 2012 Express (5 user per server)http://www.microsoft.com/visualstudio/eng/products/visual-studio-team-foundation-server-express#product-express-tfs-requirements
  • Demo TFS 2012 and Windows StoreApps
  • 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
  • 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)
  • Globalization <ToolTip x:Uid=“PreviewCartoonizeAppBarButtonToolTip” Content=“Preview Cartoonization” … />
  • GlobalizationA. Globalizing your apphttp://msdn.microsoft.com/en-us/library/windows/apps/hh465006.aspxB. How to use the Multilingual App Toolkithttp://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj572370.aspxC. Application resources and localization samplehttp://code.msdn.microsoft.com/windowsapps/Application-resources-and-cd0c6eaa
  • Demo Windows Store AppsGlobalization
  • LoggingLogging Sample for Windows Store Apps (ETW Logging in WinRT)http://code.msdn.microsoft.com/windowsapps/Logging-Sample-for-Windows-0b9dffd7MetroLog OverviewMetroLog is a lightweight logging framework designed for Windows Storeand Windows Phone 8 appshttps://github.com/mbrit/MetroLog
  • Demo Windows Store Apps Logging
  • async & await are your friends1: async Task<int> AccessTheWebAsync()2: {3: HttpClient client = new HttpClient();4: Task<string> getStringTask = client.GetStringAsync("http://msdn.microsoft.com");5: DoIndependentWork();6:7: string urlContents = await getStringTask;8: return urlContents.Length;9: }
  • Model-View-ViewModel Pattern
  • From MVC to MVVM DataBinding Commands Services Messages Events
  • ViewModel  View Behaviour BindingLoose coupling, more flexibilityBehavior is highly Blendable
  • ViewModel  View (Win8)No behaviors in Windows 8 Workaround: Use properties and binding PropertyChanged event Binding PropertyChanged
  • Focus on AttachedBehaviors• No Blend Behavior<T>• No BindingExpressions• Break out your AttachedBehavior experience and ROCK ON!
  • View services ISelectFilesService injection
  • MVVM Light
  • 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)); } }}
  • Commanding vs ViewModel MethodInvocationICommand: void Execute(object) bool CanExecute(object) event EventHandler CanExecuteChangedCommand Invoker: ButtonBase-----------------------------------------------------Event -> Action
  • Use DelegateCommand for controls thatsupport ICommandView:<Button Content=“Go to shopping cart” Command="{Binding ShoppingCartNavigationCommand}" />ViewModel:ShoppingCartNavigationCommand = newDelegateCommand(NavigateToShoppingCartPage, CanNavigateToShoppingCartPage);ShoppingCartNavigationCommand.RaiseCanExecuteChanged();
  • 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;
  • Use the Kona ViewModelLocator• Convention based lookup• Ability to override convention with exceptions to rule• Can leverage container to instantiate ViewModels.
  • 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
  • Use EventAggregator whennecessarypublic SubscriberViewModel(IEventAggregator eventAggregator){ eventAggregator.GetEvent<ShoppingCartUpdatedEvent>() .Subscribe(s => UpdateItemCountAsync());}public PublisherViewModel(IEventAggregator eventAggregator){ _eventAggregator = eventAggregator;}_eventAggregator.GetEvent<ShoppingCartUpdatedEvent>() .Publish(string.Empty);
  • Navigation: View or ViewModel FirstView First:this.Frame.Navigate(typeof(ItemDetailPage), itemId);ViewModel First:Var itemDetailPageViewModel = new ItemDetailPageViewModel(…) { ItemId = itemId };navigationService.Navigate(itemDetailPageViewModel);
  • Pages and Navigation
  • 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)
  • Navigation & Visual State SupportXAML:<Button Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/><UserControl Loaded="StartLayoutUpdates" Unloaded="StopLayoutUpdates">
  • 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); }}
  • 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>
  • 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}"/>
  • 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; }}
  • Suspend, Resume, and Terminate
  • 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
  • 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>
  • File System Local Data (SQLite) Roaming Data Hi Priority Roaming Data Password Vault Symposium 2013
  • Final Tips Read Windows 8 SDK  http://msdn.microsoft.com/library/windows/apps/ Watch Some videos  Channel 9: Windows Camps  http://channel9.msdn.com/Events/Windows-Camp  Channel 9: Windows tag  http://channel9.msdn.com/Tags/windows+8  Pluralsight windows 8 series  http://www.pluralsight.com/training/Courses#windows-8 Symposium 2013
  • Thanks! http://konaguidance.codeplex.com Symposium 2013