Conditional compilation Partial classes Dependency Injection The Windows Runtime (WinRT) is the shared runtime and API space used by store apps across the Windows.

Download Report

Transcript Conditional compilation Partial classes Dependency Injection The Windows Runtime (WinRT) is the shared runtime and API space used by store apps across the Windows.

Conditional compilation
Partial classes
Dependency Injection
The Windows Runtime (WinRT) is the
shared runtime and API space used by
store apps across the Windows platform
(phone and client)
Windows-specific
WinRT APIs
Common
WinRT APIs
Phone-specific
WinRT APIs
Dramatic convergence in 8.1
•
•
•
Goal is 100% convergence for dev scenarios
In 8.0, we had ~30% API convergence
With 8.1, we move well past 90%+ convergence
5
HTML
XAML
HTML
JavaScript Code
WinJS
Win32
Silverlight XAML
XAML
Windows Runtime XAML
C++ Code
Windows Phone
Silverlight XAML
C#/VB Code
C#/VB Code
.NET for Windows
Store
Silverlight .NET
WinRT
Windows Phone 8.1 App
Windows 8.1 App
XAML View
Phone UI
XAML View
Windows UI
Shared Code, Images, Files
WinRT
Windows Phone 8.1 App
XAML View
XAML UI
Windows 8.1 App
?
XAML View
XAML UI
Logic
Logic
Logic
Data
Data
Data
Most File Types
Libraries & Windows Runtime Components
Code files
XAML
Images
XML/JSON
RESW
Supports WinRT APIs
Expose libraries to C++, Javascript apps
Supports WinRT APIs
Expose libraries to C++, Javascript apps
Compiler conditionals to share across
additional platforms
Decouple UI from logic
plus platform specific API sets (some geolocation, media, sensors)
plus XAML components that “make sense”
Windows 8.1
Windows Only
WinRT
e.g. search contract
e.g. multiple windows
e.g. resizable windows
e.g. printing support
Windows Phone 8.1
Phone Only
WinRT
e.g. action center
e.g. status bar
e.g. back key handling
some common APIs may have different behaviour across Windows/Phone
files & settings: local, temp, roaming, pickers…
store: app purchases, receipts…
lifecycle: launch, suspend, resume, background tasks
notifications: tiles, toasts, badges, push
sensors: gps, geofencing, gyro, compass…
network: http, websockets, sockets…
localisation: resource resolution from XAML/code…
//Create the picker object
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation =
PickerLocationId.PicturesLibrary;
// Users expect to have a filtered view of their folders
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".png");
// Open the picker for the user to pick a file
StorageFile file =
await openPicker.PickSingleFileAsync();
if (file != null)
{
// Do something with the file...
}
//Create the picker object
FileOpenPicker openPicker = new FileOpenPicker();
// On Windows Phone, setting Filtering to image types
// causes Picker to show Camera Roll
openPicker.FileTypeFilter.Add(".jpg");
openPicker.FileTypeFilter.Add(".png");
// Open the picker for the user to pick a file
openPicker.PickSingleFileAndContinue();
100%
100%
No: Location (Windows) vs. Geopoint (WP)
No: Bing Maps (Windows) vs. WinRT Map control (WP)
Windows = WINDOWS_APP
Windows Phone = WINDOWS_PHONE_APP
#if WINDOWS_PHONE_APP
Windows.Phone.UI.Input.HardwareButtons.BackPressed +=
this.HardwareButtons_BackPressed;
#endif
/// <summary>
/// DataSource.cs
/// </summary>
public partial class DataSource :IDataSource {
public async Task<IEnumerable<IFolder>> RetrieveFolders(IFolder root) {
... // other logic
var folders = await LoadFolders(root);
... // other logic
return folders
}
}
/// <summary>
/// DataSource.WP.cs
/// </summary>
public partial class DataSource {
private async Task<IEnumerable<IFolder>> LoadFolders(IFolder root) {
...
}
}
HERE maps on Windows (8.1)/Phone (8.0)
common,
same rendering
common,
different content
common,
different rendering
unique
Button
Hub
DatePicker
SearchBox
Slider
Pivot
ContentDialog
AutoSuggestBox
etc.
ToggleSwitch
TimePicker
CommandBar
AppBar
etc.
ProgressBar
etc (many more)
ListView
GridView
etc.
#if WINDOWS_APP
var result = VisualStateManager.GoToState(this, "Windows", false);
#elif WINDOWS_PHONE_APP
var result = VisualStateManager.GoToState(this, "WindowsPhone", false);
#endif
<Application
x:Class="FlickrSearch.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:FlickrSearch">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="CustomDictionary.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
<TextBlock Text="{Binding Title}"
Style="{StaticResource MonTextblock}"/>
<FlipView ItemsSource="{Binding Items}"
ItemTemplate="{StaticResource APhotoTemplate}">
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:FlickrSearch">
<Style x:Key="MonTextblock" TargetType="TextBlock">
<Setter Property="Foreground" Value="DeepPink"></Setter>
</Style>
<DataTemplate x:Name="APhotoTemplate">
<Grid>
<Image Source="{Binding Path}" VerticalAlignment="Top" />
<TextBlock TextWrapping="Wrap" Text="{Binding Title}" FontSize="28" Margin="10"/>
</Grid>
</DataTemplate>
</ResourceDictionary>
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:FlickrSearch">
<Style x:Key="MonTextblock" TargetType="TextBlock">
<Setter Property="Foreground" Value="Red"></Setter>
</Style>
<DataTemplate x:Name="APhotoTemplate">
<Grid>
<Image Source="{Binding Path}" VerticalAlignment="Top" />
</Grid>
</DataTemplate>
</ResourceDictionary>
Sync engine transfers data
periodically based on
triggers (user idle, battery,
network, etc.)
Roaming
Local
Temp
WP 8.1 App – PFN 12345
PFN 12345
Roaming
folder
Roaming
settings
OneDrive stores up to 100kb of roaming
data per app (not included in user quota).
If app exceeds the limit, sync stops.
App writes data using standard
file/settings APIs.
Other clients are notified of
updated data via Windows
Notification Service. If app is
running when sync occurs, an
event is raised.
Temp
Local
Roaming
Windows App – PFN 12345
Windows.Storage.ApplicationDataContainer roamingSettings =
Windows.Storage.ApplicationData.Current.RoamingSettings;
// saving settings...
roamingSettings.Values["userName"] = someData;
// fetching settings...
if (roamingSettings.Values.ContainsKey("userName"))
{
userName = roamingSettings.Values["userName"].ToString();
}
Windows.Storage.ApplicationData.Current.DataChanged += Current_DataChanged;
...
void Current_DataChanged(ApplicationData sender, object args)
{
// Refresh your settings...
}
The event is only fired if the application is active at the time
of the change
You should still load up all your data when your app starts
Conditional compilation
Partial classes
Dependency Injection
windows.com/enterprise
windowsphone.com/business
microsoft.com/springboard
microsoft.com/mdop
microsoft.com/windows/wtg
developer.windowsphone.com
http://channel9.msdn.com/Events/TechEd
www.microsoft.com/learning
http://microsoft.com/technet
http://microsoft.com/msdn