Weitere ähnliche Inhalte Ähnlich wie ユニバーサル Windows アプリ開発 (20) Mehr von Akira Onishi (12) Kürzlich hochgeladen (20) ユニバーサル Windows アプリ開発27. #if WINDOWS_APP
var result = VisualStateManager.GoToState(this, "Windows", false);
#elif WINDOWS_PHONE_APP
var result = VisualStateManager.GoToState(this, "WindowsPhone", false);
#endif
29. <ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:PhotoSearch">
<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:PhotoSearch">
<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>
PhotoSearch.Windows/CustomDictionary.xaml
PhotoSearch.WindowsPhone/CustomDictionary.xaml
PhotoSearch.Shared/MainPage.xaml
<TextBlock Text="{Binding Title}"
Style="{StaticResource MonTextblock}"/>
<FlipView ItemsSource="{Binding Items}"
ItemTemplate="{StaticResource APhotoTemplate}">
32. Partial classes
cleaner code
Solution 'App1'
App1_Phone81
App1_Windows81
Class1.cs
References
References
App1_Shared
ViewModel.cs
ViewModel.cs
ViewModel.cs
App1_Shared
App1_Shared
Solution 'App1'
App1_Phone81
App1_Windows81
Class1.cs
References
App1_PCL
References
App1_PCL
App1_PCL
IAbstraction.cs
PhoneImpl.cs
WinImpl.cs
Inversion of Control (IOC)
purist; works also with PCL
Solution 'App1'
App1_Phone81
App1_Windows81
Class1.cs
References
App1_Shared
References
App1_Shared
App1_Shared
#if block
quick and dirty
#if WINDOWS_PHONE_APP
StatusBar.GetForCurrentView().HideAsync();
Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareBackPressed;
#endif
#if WINAPI_FAMILY==WINAPI_FAMILY_PHONE_APP
StatusBar::GetForCurrentView()->HideAsync();
#endif
33. Partial classes
cleaner code
Solution 'App1'
App1_Phone81
App1_Windows81
Class1.cs
References
References
App1_Shared
ViewModel.cs
ViewModel.cs
ViewModel.cs
App1_Shared
App1_Shared
Solution 'App1'
App1_Phone81
App1_Windows81
Class1.cs
References
App1_PCL
References
App1_PCL
App1_PCL
IAbstraction.cs
PhoneImpl.cs
WinImpl.cs
Inversion of Control (IOC)
purist; works also with PCL
Solution 'App1'
App1_Phone81
App1_Windows81
Class1.cs
References
App1_Shared
References
App1_Shared
App1_Shared
#if block
quick and dirty
#if WINDOWS_PHONE_APP
StatusBar.GetForCurrentView().HideAsync();
#endif
// I can provide my own implementation of the missing APIs !!!
namespace Windows.UI.ViewManagement
{
public class StatusBar
{
static StatusBar dummy = new StatusBar();
public static StatusBar GetForCurrentView() { return dummy; }
public async Task HideAsync() {}
}
}
34. Partial classes
cleaner code
Solution 'App1'
App1_Phone81
App1_Windows81
Class1.cs
References
References
App1_Shared
ViewModel.cs
ViewModel.cs
ViewModel.cs
App1_Shared
App1_Shared
Solution 'App1'
App1_Phone81
App1_Windows81
Class1.cs
References
App1_PCL
References
App1_PCL
App1_PCL
IAbstraction.cs
PhoneImpl.cs
WinImpl.cs
Inversion of Control (IOC)
purist; works also with PCL
Solution 'App1'
App1_Phone81
App1_Windows81
Class1.cs
References
App1_Shared
References
App1_Shared
App1_Shared
#if block
quick and dirty
// Windows¥ViewModel.cs
public partial class ViewModel
{
async Task HideStatusBarAsync() { }
}
// Phone¥ViewModel.cs
public partial class ViewModel
{
async Task HideStatusBarAsync()
{
await StatusBar.GetForCurrentView()
.HideAsync();
}
}
// Shared¥Class1.cs
await viewModel.HideStatusBarAsync();
35. Partial classes
cleaner code
Solution 'App1'
App1_Phone81
App1_Windows81
Class1.cs
References
References
App1_Shared
ViewModel.cs
ViewModel.cs
ViewModel.cs
App1_Shared
App1_Shared
Solution 'App1'
App1_Phone81
App1_Windows81
Class1.cs
References
App1_PCL
References
App1_PCL
App1_PCL
IAbstraction.cs
PhoneImpl.cs
WinImpl.cs
Inversion of Control (IOC)
purist; works also with PCL
Solution 'App1'
App1_Phone81
App1_Windows81
Class1.cs
References
App1_Shared
References
App1_Shared
App1_Shared
#if block
quick and dirty
// Shared
public interface IPlatformAbstractionLayer
{
Task HideStatusBarAsync();
}
await pal.HideStatusBarAsync();
// Windows¥WinImpl.cs
public class WindowsPAL: IPlatformAbstractionLayer
{
async Task HideStatusBarAsync() { }
}
// Phone¥PhoneImpl.cs
public class PhonePAL : IPlatformAbstractionLayer
{
async Task HideStatusBarAsync()
{
await StatusBar.GetForCurrentView()
.HideAsync();
}
}
45. // プラットフォームの判定と
// 利用するクラスの決定
if (! {
} else {
}
<!– Shared.UI.Hub, Shared.UI.HubSection で抽象化 ->
<section "Shared.UI.Hub">
<div "Shared.UI.HubSection"
"{header: 'Section1'}">
<div "Controls.Section1"></div>
</div>
<div "Shared.UI.HubSection"
"{header: 'Section2'}">
<div "Controls.Section2"></div>
</div>
</section>
// Shared.UI.Hub, Shared.UI.HubSection の定義
WinJS.Namespace.define('Shared.UI', {
Hub: hub,
HubSection: hubSection
});
46. Phone アプリ – PFN 12345
roaming Local Temp
Windows アプリ – PFN 12345
roamingLocalTemp
Local
Cache
PFN 12345
ローミング
OneDrive stores up to 100kb of roaming
data per app (not included in user quota).
If app exceeds the limit, sync stops.
Sync engine transfers data
periodically based on
triggers (user idle, battery,
network, etc.)
Other clients are notified of
updated data via Windows
Notification Service. If app is
running when sync occurs, an
event is raised.
47. private void OnSuspending(object sender, SuspendingEventArgs e)
{
// TODO: Save application state and stop any background activity
ApplicationData.Current.RoamingSettings.Values["Hoge"] = model.Hoge;
ApplicationData.Current.RoamingSettings.Values["Foo"] = model.Foo;
}
// TODO: Load state from previously suspended application
model.Hoge = (bool?)ApplicationData.Current.RoamingSettings.Values["Hoge"] ?? false;
model.Foo = (double?)ApplicationData.Current.RoamingSettings.Values["Foo"] ?? 1.0;