patronage 2016 windows 10 warsztaty

41
Warsztaty Windows 10 UWP Hubert Taler Tomasz Szczuko

Upload: intive

Post on 13-Apr-2017

366 views

Category:

Software


6 download

TRANSCRIPT

Page 1: Patronage 2016 Windows 10 Warsztaty

Warsztaty Windows 10 UWPHubert TalerTomasz Szczuko

Page 2: Patronage 2016 Windows 10 Warsztaty

● Informacje o środowisku pracy programisty● WPF - co to właściwie jest? Kontrolki, layout

● Informacje o architekturze MVVM

● Pierwsza aplikacja MVVM -> live coding

● MVVM Light

● Aplikacja uniwersalna - co to jest?

● Aplikacja uniwersalna, Adaptive triggers, RelativePanel -> live coding

● Wasze pytania

Page 3: Patronage 2016 Windows 10 Warsztaty
Page 4: Patronage 2016 Windows 10 Warsztaty

● Informacje o środowisku pracy programisty

● WPF - co to właściwie jest? Kontrolki, layout● Informacje o architekturze MVVM

● Pierwsza aplikacja MVVM -> live coding

● MVVM Light

● Aplikacja uniwersalna - co to jest?

● Aplikacja uniwersalna, Adaptive triggers, RelativePanel -> live coding

● Wasze pytania

Page 5: Patronage 2016 Windows 10 Warsztaty

WPFWindows Presentation Foundation (WPF) – nazwa silnika graficznego i API bazującego na .NET 3.

WPF integruje interfejs użytkownika, grafikę 2D i 3D,multimedia, dokumenty (nazwa kodowa Metro) oraz

generowanie/rozpoznawanie mowy.

API w WPF opiera się na języku XML, dokładniej na jego implementacji o nazwie XAML

<StackPanel x:Name="contentPanel" Margin="8,32,0,0"> <TextBlock Text="Hello, world!" Margin="0,0,0,40"/> <TextBlock Text="What's your name?"/> <StackPanel x:Name="inputPanel" Orientation="Horizontal" Margin="0,20,0,20"> <TextBox x:Name="nameInput" Width="280" HorizontalAlignment="Left"/> <Button x:Name="inputButton" Content="Say &quot;Hello&quot;"/> </StackPanel> <TextBlock x:Name="greetingOutput"/></StackPanel>

Page 6: Patronage 2016 Windows 10 Warsztaty

WPF - Przegląd kontrolek

Panele :

● Grid - układ tabelaryczny (kolumny, wiersze)● StackPanel - poziome lub pionowe rozmieszczenie● WrapPanel - zwijany StackPanel● DockPanel - panel dokujący● Canvas - obszar roboczy

● Hub - nagłówek, sekcje

● RelativePanel - UWP● SplitView - UWP

Page 7: Patronage 2016 Windows 10 Warsztaty

● Informacje o środowisku pracy programisty

● WPF - co to właściwie jest? Kontrolki, layout

● Informacje o architekturze MVVM● Pierwsza aplikacja MVVM -> live coding

● MVVM Light

● Aplikacja uniwersalna - co to jest?

● Aplikacja uniwersalna, Adaptive triggers, RelativePanel -> live coding

● Wasze pytania

Page 8: Patronage 2016 Windows 10 Warsztaty
Page 9: Patronage 2016 Windows 10 Warsztaty

Różnice między wzorcami

W MVC kontroler obsługuje zdarzenia, manipuluje modelem, który zawiera logikę biznesową, widok wyświetla dane z modelu. Jeden kontroler obsługuje kilka widoków.

W MVP dane z modelu są przekazywane do presentera a nie bezpośrednio do widoku, presenter przekazuje je do widoku. Jeden presenter odnosi się do jednego widoku.

W MVVM dane z modelu są przekazywane do VievModelu, który może obsługiwać kilka widoków. Widok nie wie nic o ViewModelu, wymaga tylko potrzebnych danych.

Page 10: Patronage 2016 Windows 10 Warsztaty
Page 11: Patronage 2016 Windows 10 Warsztaty

MVVM

● It separates the business and presentation layers, like MVP and MVC.

● Improve Structure/separation of concerns (View, ViewModel and Model).

● Enable a better Design/Developer Workflow.

● Enhance simplicity and testability.

● Enabled by the robust data binding capability of XAML.

● No need to use a code behind file (minimalist code-behind file).

● Provides application development ability for multiple environments.

● Powerful Data Binding, command, validation and much more.

● The designer and developer can work together.

Page 12: Patronage 2016 Windows 10 Warsztaty

Wady MVVM

● komplikacja kodu - ViewModel nie może komunikować się z warstwą View, co w pewnych sytuacjach bardzo komplikuje powiązania,

● do obsługi jednego widoku należy tworzyć wiele klas, co sprawia że projekt jest bardziej rozbudowany,

● duża ilość klas bazowych.

Page 13: Patronage 2016 Windows 10 Warsztaty

● Informacje o środowisku pracy programisty

● WPF - co to właściwie jest? Kontrolki, layout

● Informacje o architekturze MVVM

● Pierwsza aplikacja MVVM -> live coding● MVVM Light

● Aplikacja uniwersalna - co to jest?

● Aplikacja uniwersalna, Adaptive triggers, RelativePanel -> live coding

● Wasze pytania

Page 14: Patronage 2016 Windows 10 Warsztaty

Model

public class Person

{

public String FirstName { get; set; }

public String LastName { get; set; }

public Person(String First, String Last)

{

FirstName = First;

LastName = Last;

}

}

Page 15: Patronage 2016 Windows 10 Warsztaty

View Model

public ObservableCollection<Person> Persons { get; set; }

public PersonViewModel()

{

Persons = new ObservableCollection<Person>()

{

new Person("Jan", "Kowalski"),

new Person("John","Smith")

};

}

Page 16: Patronage 2016 Windows 10 Warsztaty

View

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<ListView ItemsSource="{Binding Persons}">

<ListView.ItemTemplate>

<DataTemplate>

<StackPanel Orientation="Horizontal">

<TextBox Height="23" Name="FirstName" Text="{Binding FirstName}" Width="120" />

<TextBox Height="23" Name="LastName" Text="{Binding LastName}" Width="120" />

<Button Command="{Binding SaveCmd}" Height="30" Width="80">Zapisz</Button>

</StackPanel>

</DataTemplate>

</ListView.ItemTemplate>

</ListView>

</Grid>

Page 17: Patronage 2016 Windows 10 Warsztaty

● Informacje o środowisku pracy programisty

● WPF - co to właściwie jest? Kontrolki, layout

● Informacje o architekturze MVVM

● Pierwsza aplikacja MVVM -> live coding

● MVVM Light● Aplikacja uniwersalna - co to jest?

● Aplikacja uniwersalna, Adaptive triggers, RelativePanel -> live coding

● Wasze pytania

Page 18: Patronage 2016 Windows 10 Warsztaty
Page 19: Patronage 2016 Windows 10 Warsztaty

<Window x:Class="WpfApplication1.MainWindow"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:vm="clr-namespace:WpfApplication1.ViewModel"

Title="MainWindow" Height="350" Width="525">

<Grid DataContext="{Binding MainViewModel, Source={StaticResource Locator}}"/>

</Window>

Page 20: Patronage 2016 Windows 10 Warsztaty

● Informacje o środowisku pracy programisty

● WPF - co to właściwie jest? Kontrolki, layout

● Informacje o architekturze MVVM

● Pierwsza aplikacja MVVM -> live coding

● MVVM Light

● Aplikacja uniwersalna - co to jest?● Aplikacja uniwersalna, Adaptive triggers, RelativePanel -> live coding

● Wasze pytania

Page 21: Patronage 2016 Windows 10 Warsztaty
Page 22: Patronage 2016 Windows 10 Warsztaty
Page 23: Patronage 2016 Windows 10 Warsztaty

● Informacje o środowisku pracy programisty

● WPF - co to właściwie jest? Kontrolki, layout

● Informacje o architekturze MVVM

● Pierwsza aplikacja MVVM -> live coding

● MVVM Light

● Aplikacja uniwersalna - co to jest?

● UWP, Adaptive triggers -> live coding● Wasze pytania

Page 24: Patronage 2016 Windows 10 Warsztaty

if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent(

"Windows.Phone.UI.Input.HardwareButtons"))

{

Windows.Phone.UI.Input.HardwareButtons.CameraPressed +=

HardwareButtons_CameraPressed;

}

Page 25: Patronage 2016 Windows 10 Warsztaty

public Platform DetectPlatform()

{

bool isHardwareButtonsAPIPresent = ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons");

if (isHardwareButtonsAPIPresent)

{

return Platform.WindowsPhone;

} else

{

return Platform.Windows;

}

}

Page 26: Patronage 2016 Windows 10 Warsztaty

if (Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily == "Windows.Mobile")

{

// code for phone

}

else

{

// other code

}

Page 27: Patronage 2016 Windows 10 Warsztaty

AdaptiveTrigger - live coding

<Grid x:Name="LayoutRoot"> <VisualStateManager.VisualStateGroups> <VisualStateGroup> <VisualState x:Name="WideState"> <VisualState.StateTriggers> <AdaptiveTrigger MinWindowWidth="600" /> </VisualState.StateTriggers> <VisualState.Setters> <Setter Target="LayoutRoot.Background" Value="Green" /> </VisualState.Setters> </VisualState> <VisualState x:Name="NarrowState"> <VisualState.StateTriggers> <AdaptiveTrigger MinWindowWidth="0" /> </VisualState.StateTriggers> <VisualState.Setters> <Setter Target="LayoutRoot.Background" Value="Red" /> </VisualState.Setters> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups></Grid>

Page 28: Patronage 2016 Windows 10 Warsztaty

● Informacje o środowisku pracy programisty

● WPF - co to właściwie jest? Kontrolki, layout

● Informacje o architekturze MVVM

● Pierwsza aplikacja MVVM -> live coding

● MVVM Light

● Aplikacja uniwersalna - co to jest?

● UWP, RelativePanel -> live coding● Wasze pytania

Page 29: Patronage 2016 Windows 10 Warsztaty

<RelativePanel BorderBrush="Gray" BorderThickness="10"> <Rectangle x:Name="RedRect" Fill="Red" MinHeight="100" MinWidth="100"/> <Rectangle x:Name="BlueRect" Fill="Blue" MinHeight="100" MinWidth="100" RelativePanel.RightOf="RedRect" /> <!-- Width is not set on the green and yellow rectangles. It's determined by the RelativePanel properties. --> <Rectangle x:Name="GreenRect" Fill="Green" MinHeight="100" Margin="0,5,0,0" RelativePanel.Below="RedRect" RelativePanel.AlignLeftWith="RedRect" RelativePanel.AlignRightWith="BlueRect"/> <Rectangle Fill="Yellow" MinHeight="100" RelativePanel.Below="GreenRect" RelativePanel.AlignLeftWith="BlueRect" RelativePanel.AlignRightWithPanel="True"/></RelativePanel>

RelativePanel

Page 30: Patronage 2016 Windows 10 Warsztaty

RelativePanel

<RelativePanel> <Rectangle x:Name="Red" Height="100" Width="200" Fill="Red"/>

<Rectangle x:Name="Blue" Height="100" Width="100" Fill="Blue" RelativePanel.Below="Red" RelativePanel.AlignRightWith="Red"/>

</RelativePanel>

Page 31: Patronage 2016 Windows 10 Warsztaty

RelativePanel - priorytety

● Panel alignment relationships (AlignTopWithPanel, AlignLeftWithPanel ...)

● Sibling alignment relationships (AlignTopWith, AlignLeftWith ...)

● Sibling positional relationships (Above, Below, RightOf, LeftOf)

Page 32: Patronage 2016 Windows 10 Warsztaty

RelativePanel - zagrożenie 1

<RelativePanel> <Rectangle x:Name="Red" Height="100" Width="200" Fill="Red"/>

<Rectangle x:Name="Blue" Height="100" Width="100" Fill="Blue" RelativePanel.Below="Red" RelativePanel.LeftOf="Red"/>

</RelativePanel>

Page 33: Patronage 2016 Windows 10 Warsztaty

RelativePanel - zagrożenie 2

<RelativePanel>

<Rectangle x:Name="Red" Height="100" Width="200" Fill="Red" RelativePanel.AlignHorizontalCenterWith="Blue" RelativePanel.LeftOf="Blue"/>

<Rectangle x:Name="Blue" Height="100" Width="100" Fill="Blue" RelativePanel.AlignHorizontalCenterWithPanel="True" RelativePanel.AlignVerticalCenterWithPanel="True"/>

</RelativePanel>

Page 34: Patronage 2016 Windows 10 Warsztaty

RelativePanel - zagrożenie 3

<RelativePanel> <Rectangle x:Name="Red" Height="100" Width="200" Fill="Red" RelativePanel.Above="Blue"/>

<Rectangle x:Name="Blue" Height="100" Width="100" Fill="Blue" RelativePanel.Below="Red"/>

</RelativePanel>

Page 35: Patronage 2016 Windows 10 Warsztaty

RelativePanel - Live coding…

<RelativePanel HorizontalAlignment="Stretch" Margin="20"> <TextBlock Text="First name" x:Name="FirstNameLabel" Margin="0,5,10,5"/> <TextBox x:Name="FirstNameText" Width="300" /> </RelativePanel>…<Setter Target="FirstNameText.(RelativePanel.RightOf)" Value="FirstNameLabel" /> ...<Setter Target="FirstNameText.(RelativePanel.Below)" Value="FirstNameLabel" />...

Page 36: Patronage 2016 Windows 10 Warsztaty

● Informacje o środowisku pracy programisty

● WPF - co to właściwie jest? Kontrolki, layout

● Informacje o architekturze MVVM

● Pierwsza aplikacja MVVM -> live coding

● MVVM Light

● Aplikacja uniwersalna - co to jest?

● UWP, DeviceFamily specific views -> live coding● Wasze pytania

Page 37: Patronage 2016 Windows 10 Warsztaty

DeviceFamily specific views - Type folder

Page 38: Patronage 2016 Windows 10 Warsztaty

DeviceFamily specific views - Type in file name

Page 39: Patronage 2016 Windows 10 Warsztaty

DeviceFamily specific views - overloadpublic MainPage() { if (AnalyticsInfo.VersionInfo.DeviceFamily == "Windows.Mobile") { if (usePrimary) { InitializeComponent(new Uri("ms-appx:///PrimaryMainPage.xaml", UriKind.Absolute)); } else { InitializeComponent(new Uri("ms-appx:///SecondaryMainPage.xaml", UriKind.Absolute)); } } else { InitializeComponent(); }}

Page 40: Patronage 2016 Windows 10 Warsztaty

● Informacje o środowisku pracy programisty

● WPF - co to właściwie jest? Kontrolki, layout

● Informacje o architekturze MVVM

● Pierwsza aplikacja MVVM -> live coding

● MVVM Light

● Aplikacja uniwersalna - co to jest?

● Aplikacja uniwersalna, Adaptive triggers, RelativePanel -> live coding

● Wasze pytania

Page 41: Patronage 2016 Windows 10 Warsztaty

Thank you!