Windows 8.1 RTM + Visual Studio 2013æç¹ã®æ å ±ã§ã
Windows ã¹ã㢠ã¢ããªã®éçºã¯ããã³ãã¬ã¼ãã«å¾ã£ã¦ããã®ãä¸çªã®è¿éã§ãããã ãWindows 8ã¨Windows 8.1ã§ãã³ãã¬ã¼ãã®ä¸èº«ãçµæ§å¤ããã¾ãããã©ããããå¤ãã£ããã¨ããã¨ãCommonãã©ã«ãã®ä¸èº«ã以ä¸ã®ããã«å¤ãã£ã¦ã¾ãã
Windows 8
- BindableBase.cs
- BooleanNegationConverter.cs
- BooleanToVisibilityConverter.cs
- LayoutAwarePage.cs
- RichTextColumns.cs
- StandardStyles.xaml
- SuspensionManager.cs
Windows 8.1
- NavigationHelper.cs
- ObservableDictionary.cs
- RelayCommand.cs
- SuspensionManager.cs
ä½ãå¤ãã£ãã®ï¼
ãããä½ãå¤ãã£ã¦ãªãã®ããæ¢ãã»ããæ©ãæãã§ããSuspensionManagerã¯æ©è½çã«ã¯åãã§ããã³ã¼ãã®diffãã¨ã£ãããã§ã¯ãªãã§ãããã©ã¡ãã258è¡ã®ã³ã¼ãã§ããããã¨ã¯å¤ãã£ã¦ã¾ããConverterããLayoutAwarePageãStandardStyles.xamlã®ãã¨ã¯å¿ãã¾ãããã
LayoutAwarePageã¯ã©ãã«ãã£ã
Windows 8ã®é ã¯ãåºæ¬çã«LayoutAwarePageãç¶æ¿ããã¯ã©ã¹ã使ã£ã¦ç»é¢ãä½ã£ã¦ãã¾ãããWindows 8.1ã§ã¯ããããè¾ãã¦æ®éã®Pageã¯ã©ã¹ãç¶æ¿ããã¯ã©ã¹ã使ãã¾ããã§ã¯ãLayoutAwarePageã§æä¾ãã¦ããç»é¢é·ç§»ã®å±¥æ´ã®ä¿æetc...ã®æ§ã ãªæ©è½ã¯ã©ãã«ãã£ãã®ãã¨ããã¨ãNavigationHelperã¯ã©ã¹ã«ç§»åããã¦ãã¾ãã
ç¶æ¿ããå§è²ã¸
Windows 8ã®ãã¼ã¸ã®ãã³ãã¬ã¼ãã®å°ã£ãã¨ããã¯ãLayoutAwarePageã«ä¾åããªããã¼ã¸ãä½ããã¨æã£ãããã¬ã¼ã³ãªä½ãç¡ã空ç½ã®ãã¼ã¸ããã¼ã¹ã«ä½ããªããã°ãªãã¾ããã§ããããã®ä»ã®ãã¼ã¸ã¯å ¨ã¦LayoutAwarePageãç¶æ¿ãã¦ããããããããæ¸ãæãã¦æ®éã®Pageãèªåã®Pageã®åºæ¬ã¯ã©ã¹ã«å·®ãæ¿ããã®ã¯çµæ§éª¨ã®æããä½æ¥ã§ããLayoutAwarePageã«ä¾åããªãéçºããããªããã¢ã¤ãã ãã³ãã¬ã¼ããèªä½ããªãã¨ç¾å®çãããªããããã§ãã
å®éã«Prism for Windows Runtimeã§ã¯ãç»å ´å½åã¯ãã³ãã¬ã¼ãã®æ¸ãæãæé ã示ãã¦ãã¾ããããæ«ããã¦ä¸ã®äººãã¢ã¤ãã ãã³ãã¬ã¼ãã¨ããã¸ã§ã¯ããã³ãã¬ã¼ããæä¾ãã¦ããã¾ãããããã®ãããã§å¤§å楽ã«ä½ããããã«ãªãã¾ããã
Windows 8.1ã§ã¯ãPageã¯ã©ã¹ããNavigationHelperã¯ã©ã¹ã使ããã¨ã§ç»é¢é·ç§»ã®å±¥æ´ä¿æãªã©ã®æ©è½ãæä¾ãã¦ããã¦ãã¾ããåèã¾ã§ã«ãWindows 8.1ã®ä¸çªã·ã³ãã«ãªãã©ã³ã¯ãã¼ã¸ã®ã³ã¼ãã以ä¸ã«ç¤ºãã¾ãã
public sealed partial class BasicPage : Page { private NavigationHelper navigationHelper; private ObservableDictionary defaultViewModel = new ObservableDictionary(); /// <summary> /// ããã¯å³å¯ã«åæå®ããããã¥ã¼ ã¢ãã«ã«å¤æ´ã§ãã¾ãã /// </summary> public ObservableDictionary DefaultViewModel { get { return this.defaultViewModel; } } /// <summary> /// NavigationHelper ã¯ãããã²ã¼ã·ã§ã³ããã³ããã»ã¹ç¶ç¶æé管çã /// æ¯æ´ããããã«ãåãã¼ã¸ã§ä½¿ç¨ãã¾ãã /// </summary> public NavigationHelper NavigationHelper { get { return this.navigationHelper; } } public BasicPage() { this.InitializeComponent(); this.navigationHelper = new NavigationHelper(this); this.navigationHelper.LoadState += navigationHelper_LoadState; this.navigationHelper.SaveState += navigationHelper_SaveState; } /// <summary> /// ãã®ãã¼ã¸ã«ã¯ã移åä¸ã«æ¸¡ãããã³ã³ãã³ããè¨å®ãã¾ããåã®ã»ãã·ã§ã³ãããã¼ã¸ã /// åä½æããå ´åã¯ãä¿åç¶æ ãæå®ããã¾ãã /// </summary> /// <param name="sender"> /// ã¤ãã³ãã®ã½ã¼ã¹ (é常ã<see cref="NavigationHelper"/>)> /// </param> /// <param name="e">ãã®ãã¼ã¸ãæåã«è¦æ±ãããã¨ãã« /// <see cref="Frame.Navigate(Type, Object)"/> ã«æ¸¡ãããããã²ã¼ã·ã§ã³ ãã©ã¡ã¼ã¿ã¼ã¨ã /// åã®ã»ãã·ã§ã³ã§ãã®ãã¼ã¸ã«ãã£ã¦ä¿åãããç¶æ ã®è¾æ¸ãæä¾ãã /// ã»ãã·ã§ã³ããã¼ã¸ã«åãã¦ã¢ã¯ã»ã¹ããã¨ããç¶æ 㯠null ã«ãªãã¾ãã</param> private void navigationHelper_LoadState(object sender, LoadStateEventArgs e) { } /// <summary> /// ã¢ããªã±ã¼ã·ã§ã³ãä¸æãããå ´åãã¾ãã¯ãã¼ã¸ãããã²ã¼ã·ã§ã³ ãã£ãã·ã¥ããç ´æ£ãããå ´åã /// ãã®ãã¼ã¸ã«é¢é£ä»ããããç¶æ ãä¿åãã¾ããå¤ã¯ã /// <see cref="SuspensionManager.SessionState"/> ã®ã·ãªã¢ã«åã®è¦ä»¶ã«æºæ ããå¿ è¦ãããã¾ãã /// </summary> /// <param name="sender">ã¤ãã³ãã®ã½ã¼ã¹ (é常ã<see cref="NavigationHelper"/>)</param> /// <param name="e">ã·ãªã¢ã«åå¯è½ãªç¶æ ã§ä½æããã空ã®ãã£ã¯ã·ã§ããªãæä¾ããã¤ãã³ã ãã¼ã¿ ///ã</param> private void navigationHelper_SaveState(object sender, SaveStateEventArgs e) { } #region NavigationHelper ã®ç»é² /// ãã®ã»ã¯ã·ã§ã³ã«ç¤ºããã¡ã½ããã¯ãNavigationHelper ããã¼ã¸ã® /// ããã²ã¼ã·ã§ã³ ã¡ã½ããã«å¿çã§ããããã«ããããã«ã®ã¿ä½¿ç¨ãã¾ãã /// /// ãã¼ã¸åºæã®ãã¸ãã¯ã¯ã /// <see cref="GridCS.Common.NavigationHelper.LoadState"/> /// ããã³ <see cref="GridCS.Common.NavigationHelper.SaveState"/> ã®ã¤ãã³ã ãã³ãã©ã¼ã«é ç½®ããå¿ è¦ãããã¾ãã /// LoadState ã¡ã½ããã§ã¯ãåã®ã»ãã·ã§ã³ã§ä¿åããããã¼ã¸ã®ç¶æ ã«å ãã /// ããã²ã¼ã·ã§ã³ ãã©ã¡ã¼ã¿ã¼ã使ç¨ã§ãã¾ãã protected override void OnNavigatedTo(NavigationEventArgs e) { navigationHelper.OnNavigatedTo(e); } protected override void OnNavigatedFrom(NavigationEventArgs e) { navigationHelper.OnNavigatedFrom(e); } #endregion }
å°ããã¤è§£èª¬ãã¦ããã¾ãã
DefaultViewModelããããã£
DefaultViewModelã¨ããObservableDictionaryåã®ããããã£ãå®ç¾©ããã¦ãã¾ããObservableDictionaryã¯ã©ã¹ã¯Commonåå空éã§å®ç¾©ããã¦ãããå¤æ´éç¥æ©è½ãæã£ãDictionaryã§ããWindows 8ã®é ã¯LayoutAwarePageã§æã£ã¦ããããããã£ã«ãªãã¾ãããWindows 8.1ã§ã¯ããã¼ã¸ã«ç´æ¥å®ç¾©ãããããã«ãªãã¾ããã
ããã¯ãã åã«ãXAMLå´ã§DataContextã«Bindingããã¦ããããããã£ã«ãªãã¾ãã該å½ç®æã以ä¸ã«ç¤ºãã¾ãã
<Page ... çç¥ ... DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}" ... çç¥ ... mc:Ignorable="d">
DefaultViewModelã®ããããã£ã®ã³ã¡ã³ãã«ããã¨ãããããã®åãObservableDictionaryåããå¤ãããã¨ã§ãä»»æã®åããã¼ã¸ã®ViewModelã¨ãã¦å²ãå½ã¦ããã¨ãã§ãã¾ãã
private ObservableDictionary defaultViewModel = new ObservableDictionary(); /// <summary> /// ããã¯å³å¯ã«åæå®ããããã¥ã¼ ã¢ãã«ã«å¤æ´ã§ãã¾ãã /// </summary> public ObservableDictionary DefaultViewModel { get { return this.defaultViewModel; } }
ä¾ãã°MyViewModelã¨ããViewModelãå®ç¾©ãã¦ãããã使ãããå ´åã¯ä»¥ä¸ã®ããã«ã³ã¼ããæ¸ãæãã¾ãã
private MyViewModel defaultViewModel = new MyViewModel(); public MyViewModel DefaultViewModel { get { return this.defaultViewModel; } }
åºæ¬ã¯ã©ã¹ã§ã¯ãªãããã¼ã¸ã«å®ç¾©ãããããã«ãªã£ããã¨ã§ããã®ããã«ç°¡åã«åãå¤ãããã¨ãã§ããããã«ãªãã¾ããããã®ç¹ã¯ã¨ã£ã¦ãããã¨æãã¾ããWindows 8ã®LayoutAwarePageã®å ´åã¯ããã¼ã¸ã«ç¬èªããããã£ãå®ç¾©ãã¦ããããDataContextã«ç´ã¥ãããã¨ã§åæ§ã®ãã¨ãã§ãã¾ãããLayoutAwarePageã«å®ç¾©ãããDefaultViewModelããããã£ã¯æ®ãã£ã±ãªããªã®ã§ããªãã ãæ°æã¡æªãæãã«ãªã£ã¦ã¾ããã
NavigationHelper
ãã®ã¯ã©ã¹ã¯ãååãæã示ãéãããã²ã¼ã·ã§ã³ã§Windows ã¹ã㢠ã¢ããªãæã¤ã¹ãä¸è¬çãªåãããã¼ã¸ã¯ã©ã¹ã«ä»ä¸ãããã«ãã¼ã¯ã©ã¹ã§ããNavigationHelper.csãéãã¨ãã¯ã©ã¹ã®ããã¥ã¡ã³ãã³ã¡ã³ãã«ä½¿ç¨æ¹æ³ãæ¸ããã¦ãã¾ããããã«ããéããPageã¯ã©ã¹ã«NavigationHelperãçµã¿è¾¼ãã«ã¯ä»¥ä¸ã®ãããªã³ã¼ããPageã¯ã©ã¹ã«è¿½è¨ãã¾ãã
private NavigationHelper navigationHelper; public ã³ã³ã¹ãã©ã¯ã¿() { this.InitializeComponent(); this.navigationHelper = new NavigationHelper(this); this.navigationHelper.LoadState += navigationHelper_LoadState; this.navigationHelper.SaveState += navigationHelper_SaveState; } public NavigationHelper NavigationHelper { get { return this.navigationHelper; } } private void navigationHelper_LoadState(object sender, LoadStateEventArgs e) { } private void navigationHelper_SaveState(object sender, SaveStateEventArgs e) { } protected override void OnNavigatedTo(NavigationEventArgs e) { navigationHelper.OnNavigatedTo(e); } protected override void OnNavigatedFrom(NavigationEventArgs e) { navigationHelper.OnNavigatedFrom(e); }
åºæ¬çã«å¿ è¦ãªæä½ã¯ãNavigationHelperã¯ã©ã¹ããã£ã¼ã«ãã«æã¡ãã³ã³ã¹ãã©ã¯ã¿ã§NavigationHelperã®ã¤ã³ã¹ã¿ã³ã¹ãä½æãã¾ãããã®ã¨ãNavigationHelperã®ã³ã³ã¹ãã©ã¯ã¿ã«ãã¼ã¸èªèº«ã®ã¤ã³ã¹ã¿ã³ã¹ã渡ãã¾ãããããããã¨ã§ãã¼ã¸ã®å種ã¤ãã³ããªã©ãé©åã«å¦çãã¦LayoutAwarePageãæä¾ãã¦ããã¦ãæ©è½ã®ä¸é¨ï¼ã·ã§ã¼ãã«ãããæ»ããã¿ã³ãªã©ï¼ãæä¾ãã¦ããã¾ããNavigationHelperã¯ã©ã¹ã«ã¯GoBackCommandã¨ããã³ãã³ããæä¾ããã¦ãã¦ããããæ»ããã¿ã³ã®Commandã¨ãã¤ã³ãããã¦ãã¾ãããã®ç¹ãLayoutAwarePageå ã®GoBackã¤ãã³ããã³ãã©ãªã©ã§ãã£ã¦ããå¦çãã³ãã³ãã§ã·ã³ãã«ã«ãããããã¦ãã¦å人çã«å¥½ãã§ãã(ä¸èº«ã¯ãããªã«å¤ãããªãã§ããâ¦ï¼
次ã«ããã¼ã¸ã®å±¥æ´ããã¼ã¸ã®ä¸æãã¼ã¿ã®ä¿æãªã©ã§ãããLayoutAwarePageã®ã¨ãã¯LoadStateã¨SaveStateã¨ããã¡ã½ããããªã¼ãã¼ã©ã¤ããã¦å©ç¨ãã¦ãã¾ãããNavigationHelperã§ã¯ãLoadStateã¤ãã³ãã¨SaveStateã¤ãã³ããå®ç¾©ããã¦ãã¦ããããè³¼èªãããã¨ã§åæ§ã®å¦çãè¡ãã¾ããLoadStateã¤ãã³ãã¨SaveStateã¤ãã³ãã¯ããã¾ã©ãçããç¬èªã®delegateã¨ãã¦å®ç¾©ããã¦ãã¦ã以ä¸ã®ãããªã·ã°ããã£ãæã¡ã¾ãã
/// <summary> /// <see cref="NavigationHelper.LoadState"/> ã¤ãã³ããå¦çããã¡ã½ããã表ãã¾ã /// </summary> public delegate void LoadStateEventHandler(object sender, LoadStateEventArgs e); /// <summary> /// <see cref="NavigationHelper.SaveState"/> ã¤ãã³ããå¦çããã¡ã½ããã表ãã¾ã /// </summary> public delegate void SaveStateEventHandler(object sender, SaveStateEventArgs e);
LoadStateã¤ãã³ãã®ã¤ãã³ãå¼æ°ã§ããLoadStateEventArgsã¯ã©ã¹ã¯ä»¥ä¸ã®ããããã£ãæã£ã¦ãã¾ãã
- public object NavigationParameter { get; }
- ç»é¢é·ç§»ã§åã®ç»é¢ãã渡ããããã©ã¡ã¼ã¿ãåå¾ã§ãã¾ãã
- public Dictionary<string, Object> PageState { get; }
- 以åã«ãã®ãã¼ã¸ã§SaveStateã®ã¨ãã«è¨å®ããå¤ãå ¥ã£ãDictionaryãåå¾ãã¾ããã¯ããã¦ãã¼ã¸ã«ã¢ã¯ã»ã¹ããã¨ãã¯nullã«ãªãã¾ãã
SaveStateã¤ãã³ãã®ã¤ãã³ãå¼æ°ã§ããSaveStateEventArgsã¯ã©ã¹ã¯ä»¥ä¸ã®ããããã£ãæã£ã¦ãã¾ãã
- public Dictionary<string, Object> PageState { get; }
- ãã¼ã¸ã§ä¸æçã«ä¿åããããã¼ã¿ãè©°ããDictionaryãåå¾ãã¾ããããã§è¨å®ããå¤ãLoadStateã¤ãã³ãã®ã¨ãã«åå¾ã§ãã¾ãã
ãã®ã¤ãã³ããå¦çãããã¨ã§ãLayoutAwarePageã®ã¨ãã«LoadStateã¡ã½ããã¨SaveStateã¡ã½ããã§è¡ã£ã¦ããã®ã¨åãå¦çãå¯è½ã«ãªãã¾ãã
ObservableDictionaryã¯ã©ã¹
éç¥æ©è½ããã£ãDictionaryã§ããããã©ã«ãã®ãã¼ã¸ã®ãã³ãã¬ã¼ãã§DefaultViewModelããããã£ã«æå®ãããããã ãã«åå¨ãã¦ãã¨æããã¾ãã
RelayCommandã¯ã©ã¹
ICommandã¤ã³ã¿ã¼ãã§ã¼ã¹ã®ãããããå®è£ ã§ããExecuteã¨CanExecuteãããªã²ã¼ãã§æå®å¯è½ã§ããNavigationHelperã®GoBackCommandããããã£ãªã©ã§ä½¿ç¨ããã¦ãã¾ãã
StandardStyles.xamlã¯ã©ãã«ãã£ãï¼
æ§ã ãªåºæ¬çãªã¹ã¿ã¤ã«ãå®ç¾©ããã¦ããStandardStyles.xamlã§ããããªããªãã¾ãããæ»ããã¿ã³ãªã©ã®ãããªåºæ¬çãªããããã¹ã¿ã¤ã«ã¯ã以ä¸ã®XAMLã§å®ç¾©ããã¦ãã¾ãã
C:\Program Files (x86)\Windows Kits\8.1\Include\winrt\xaml\design\generic.xaml
ãã¼ããã¨ã®è²ãªã©ã®å®ç¾©ããã³ã³ããã¼ã«ã®ãã³ãã¬ã¼ããå®ç¾©ããã¦ãã¾ããAppBarButtonã¯ãå°ç¨ã¯ã©ã¹å®ç¾©ããããã®ã³ã³ããã¼ã«ã«ã¢ã¤ã³ã³ã®è¨å®æ©è½ãªã©ã追å ããã¦ãã¾ããXAMLã§ãã¿ã³ã®ãã³ãã¬ã¼ããå·®ãæ¿ããã ãã§AppBarã®ãã¿ã³ãä½ããã¨ã¯ãããå°ç¨ã¯ã©ã¹ãç¨æããã¦ããã»ãã楽ã§ããã
ã¾ã¨ã
ããã¸ã§ã¯ããã³ãã¬ã¼ãã«å«ã¾ãã¦ããCommonåå空éã®ã¯ã©ã¹æ§é ã大ããå¤ãã£ãï¼ããããCommonã£ã¦ãã©ã«ãããã£ã¦ãããã«çµ¶å¯¾å¿ è¦ãªæ©è½ãããã¸ã§ã¯ããã³ãã¬ã¼ããããã®ãããããã¨æã£ã¦ãï¼ã®ã§ãçµæ§æåã¯æ¸æãã¨æãã¾ãããæä¾ããã¦ãæ©è½ã¯ãããªã«å¤ããããã¾ãããã¹ãããã¨ãã8.1ã«ãªã£ã¦ç¡ããªã£ãã¶ãè¦ãããã¨ãæ¸ã£ã¦ã·ã³ãã«ã«ãªã£ããããã§ãã
ããã«ãNavigationHelperã®æ©è½ããããªãå ´åã¯å§è²ãã¦ãé¨åã®ã³ã¼ããåé¤ããã ãã§ããã®ã§ãã³ãã¬ã¼ãã«ç¸ãããªããã¼ã¸ä½ãã楽ã«ãªã£ãã®ã§çå®ã«é²æ©ãã¦ãã¨æãã¾ããã¨ãããããWindows 8.1ã®ä¸è¬å ¬éåã³ãVisual Studio 2013ã®æ£å¼çã®æä¾ã楽ãã¿ã§ããã