ãã¹ãŠã®Windowsã¹ãã¢ã¢ããªéçºè ã¯ãã¬ã€ãã©ã€ã³ãç¥ãå¿ èŠããããŸãã
è±èªãã翻蚳ãããã¬ã€ãã©ã€ã³-æšå¥šäºé ãã¬ã€ãã©ã€ã³ã ã¢ããªã±ãŒã·ã§ã³ãã¹ãã¢ã«å ¥ãããã«æšå¥šäºé ã«åŸãå¿ èŠã¯ãããŸããããæšå¥šäºé ã«åŸãããšããå§ãããŸãã ããã€ãã®æ©èœããããŸããã€ãŸããè¡šçŸãããæ©èœïŒè±èªã®æ©èœïŒããããåã¢ããªã±ãŒã·ã§ã³ã«å¿ èŠã§ãã ãããã®æ©èœãæ€èšããåæã«éçºãéå§ã§ããWindowsã¹ãã¢ã¢ããªã±ãŒã·ã§ã³ã®CïŒ/ XAMLãã³ãã¬ãŒããäœæããããšã«ããŸããã çµå±ãäœããã®æ¹æ³ã§ãç¹å®ã®æ©èœã®ã¹ããããã³ãŒããã³ããŒããããã«ã以åã«éçºãããã¢ããªã±ãŒã·ã§ã³ãŸãã¯MSDNã«é »ç¹ã«ç§»åããå¿ èŠããããŸãã
以äžã«èª¬æããæ©èœã¯ãã¢ããªã±ãŒã·ã§ã³ã«é¢é£ããã¬ã€ãã©ã€ã³ãäœæããã ãã§ãªãããŠãŒã¶ãŒã®æ³šæãåŒãä»ããããã¢ãŒã·ã§ã³ã«ã圹ç«ã€è¿œå æ©èœã§ã¢ããªã±ãŒã·ã§ã³ãè£ é£ŸããŸãã
å ±æå¥çŽ
ãŠãŒã¶ãŒãé»åã¡ãŒã«ãå人ã«éä¿¡ãããããœãŒã·ã£ã«ãããã¯ãŒã¯äžã®ã¢ããªã±ãŒã·ã§ã³/ã²ãŒã ã«é¢ããæ å ±ãå ±æãããããã«ã¯ãã¢ããªã±ãŒã·ã§ã³ã³ãŒãã«å ±æå¥çŽãè¿œå ããå¿ èŠããããŸãã ãããè¡ãã«ã¯ã次ã®æé ãå®è¡ããŸãã
åå空éãè¿œå ããŸãã
using Windows.ApplicationModel.DataTransfer;
ãããŠãããŒãžã¯ã©ã¹ã§å€æ°å®£èšãè¿œå ããŸãã
private DataTransferManager dataTransferManager;
次ã«ãããŒãžã«åºå ¥ãããã€ãã³ããåå®çŸ©ããŸãã
protected override void OnNavigatedTo(NavigationEventArgs e) { // share this.dataTransferManager = DataTransferManager.GetForCurrentView(); this.dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(this.DataRequested); } protected override void OnNavigatedFrom(NavigationEventArgs e) { // this.dataTransferManager.DataRequested -= new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(this.DataRequested); }
å ±æã§ããæãç°¡åãªã³ã³ãã³ãã¯ãèŠåºããããã¹ããããã³ãªã³ã¯ã§ãã
private void DataRequested(DataTransferManager sender, DataRequestedEventArgs e) { Uri dataPackageUri = new Uri("http://apps.microsoft.com/windows/ru-ru/app/mp3/0122ffd9-585f-4b3d-a2ad-571f74231d14"); DataPackage requestData = e.Request.Data; requestData.Properties.Title = " "; requestData.SetWebLink(dataPackageUri); requestData.Properties.Description = " - . , ."; }
ãã¡ã€ã«ãŸãã¯ç»åãéä¿¡ããããšãã§ããŸãã ã¡ãã»ãŒãžãHTML圢åŒã§éä¿¡ã§ãããªãã·ã§ã³ããããŸãã
ããžãã¯ãã£ãŒã ãœã±ãããåŒã³åºãããã®äžã®æ¬¡ã®ã¢ã€ã³ã³ãéžæããããšã«ãããWindows 8.1ããå ±æã§ããŸãã
Windows 10ã§ã¯ãã¢ããªã±ãŒã·ã§ã³ã®å·Šäžé ã«ããåãã¢ã€ã³ã³ãã¯ãªãã¯ããŠã³ã³ãã³ããå ±æã§ããŸãã
ã³ãŒãããããã°ã©ã ã§ãŠã£ã³ããŠãéãã«ã¯ã次ã®è¡ã䜿çšã§ããŸãã
Windows.ApplicationModel.DataTransfer.DataTransferManager.ShowShareUI();
å ¬åŒã¬ã€ãã¯æ¬¡ã®å Žæã«ãããŸãã
ã¯ã€ãã¯ã¹ã¿ãŒãã¬ã€ãïŒã³ã³ãã³ãå ±æïŒXAMLïŒ
ã©ã€ãã¿ã€ã«
確ãã«ãéå§ç»é¢ã®äžéšã®ã¿ã€ã«ã¯æéãšãšãã«å€åããããšã«æ°ã¥ããŸããã ããšãã°ããã¥ãŒã¹ãµã€ãã¿ã€ã«ãŸãã¯è²¡åã¢ããªã±ãŒã·ã§ã³ã¿ã€ã«ãåãäžããŸãããããã®ã¿ã€ã«èªäœãã»ãã¥ãªãã£æ å ±ãæŽæ°ããŸãã äžéšã®ã¿ã€ã«ã¯æ°ç§ããšã«å€åããããããŠãŒã¶ãŒã®æ³šæãåŒãä»ããŸãã ãããã¯ããããããã©ã€ããã¿ã€ã«/ã¿ã€ã«ã§ãã
ã¢ããªã±ãŒã·ã§ã³ãã¿ã€ã«ãå€æŽããã«ã¯ã ããã·ã¥éç¥ãéä¿¡ã§ããŸãããã¢ããªã±ãŒã·ã§ã³èªäœããã¿ã€ã«ãæŽæ°ã§ããŸãã
ã¢ããªã±ãŒã·ã§ã³ããã¿ã€ã«ãæŽæ°ããã«ã¯ãæåã«åå空éãè¿œå ããå¿ èŠããããŸã
using Windows.UI.Notifications;
次ã«ãã¿ã€ã«ã®å€èŠ³ãšããã¹ããå€æŽããç°¡åãªã¡ãœãããèšè¿°ããŸãã
void UpdateTileWithText() { // # var tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150Text04); var tileAttributes = tileXml.GetElementsByTagName("text"); string tiletext = " - "; tileAttributes[0].AppendChild(tileXml.CreateTextNode(tiletext)); var tileNotification = new TileNotification(tileXml); tileNotification.ExpirationTime = DateTimeOffset.UtcNow.AddHours(1); TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification); }
ãã®äŸã§ã¯ã4è¡ã®ããã¹ããå«ãã¿ã€ã«ããã³ãã¬ãŒããšããŠäœ¿çšãããŸããã ãã¹ãŠã®ãã¿ãŒã³ã¯ã ã¿ã€ã«ãã¿ãŒã³ã«ã¿ãã°ã§å ¥æã§ããŸãã
ã¬ã€ãã©ã€ã³ã«ãããšãã¢ããªã±ãŒã·ã§ã³ã«ã¯æ£æ¹åœ¢ãšå¹ åºã®ã¿ã€ã«ã䜿çšããããšã匷ããå§ãããŸãããããã£ãŠãåãã³ãŒããè€è£œããã¿ã€ã«ãæ£æ¹åœ¢ã§ã¯ãªãå¹ åºãšããŠãã³ãã¬ãŒããšããŠæå®ããããšããå§ãããŸãã ã€ãŸãããã®äŸã§ã¯ã TileTemplateType.TileSquare150x150Text04ãTileTemplateType.TileWide310x150Text04ã«çœ®ãæããŸãã
ç§ã®ã¢ããªã±ãŒã·ã§ã³ã§ã¯ãApp_Suspendingã€ãã³ãäžã«ã¿ã€ã«ãæŽæ°ããŠããŠãŒã¶ãŒãäœãæ¢ããããæãåºãããŸããããããã¯ãã€ã§ãã§ããŸãã
è¡ãããå€æŽãã¯ãªã¢ããã¿ã€ã«ãå ã®ãã©ãŒã ã«æ»ãå¿ èŠãããå Žåã次ã®è¡ã®ã³ãŒããããããè¡ãããšãã§ããŸãã
TileUpdateManager.CreateTileUpdaterForApplication().Clear();
å ¬åŒã§ã¯ãããŸãããç°¡æœã§ã¯ãããŸãããããå°ã詳现ãªèª¬æãããã«ãããŸãã
ã¯ã€ãã¯ã¹ã¿ãŒãã¬ã€ãïŒã¿ã€ã«æŽæ°ã®éä¿¡ïŒXAMLïŒ
è©äŸ¡ãšã¬ãã¥ãŒ
æ§ããã«ãŠãŒã¶ãŒãæåŸ ããŠã¢ããªã±ãŒã·ã§ã³ãè©äŸ¡ããããšããå§ãããŸãã è¯ãè©äŸ¡ãšã¬ãã¥ãŒã¯ããªãã¡ãŒã®äººæ°ãé«ããã®ã«åœ¹ç«ã¡ãŸãã ããã«ããŠãŒã¶ãŒã¬ãã¥ãŒã«ãããã¢ããªã±ãŒã·ã§ã³ã®æ©èœãšãã¶ã€ã³ã«ã¿ã€ã ãªãŒã§æçšãªå€æŽãå ããããšãã§ããŸãã æšå®å€ã§Windowsã¹ãã¢ãŠã£ã³ããŠãéãã«ã¯ãURIãäœæããŠéããŸãã ããã«ã¯2è¡ã§ååã§ãã
var uri = new Uri("ms-windows-store:Review?PFN=9cc1e6dd-9d82-4736-aee5-acb9a01d9c39_1dv79ndb6c382"); await Windows.System.Launcher.LaunchUriAsync(uri);
ããŒãžã¯awaitã䜿çšããŠéåæã§éãããããšã«æ³šæããŠãã ããã ãã®å Žåããã¿ã³ã®ã¯ãªãã¯æé ã«éåæè¿°èªãè¿œå ããå¿ èŠããããŸãã
URIã®çæã¯æ¯èŒçç°¡åã§ãã ãms-windows-storeïŒReviewïŒPFN = "ããšããããã¹ãã«ãããã±ãŒãžãã¡ããªåãŸãã¯ç¥ç§°PFNãè¿œå ããå¿ èŠããããŸãã ã¢ããªã±ãŒã·ã§ã³ãããã§ã¹ããéããšããã®æå³ãããããŸãã
ã¹ãã¢å ã®ã¢ããªã±ãŒã·ã§ã³ãžã®ãªã³ã¯ãäœæããæ¹æ³ã®å ¬åŒã¬ã€ããžã®ãªã³ã¯ïŒ
ã¢ããªãžã®ãªã³ã¯
ããŒã¯ãŒãããã·ã¢èªã®ç¿»èš³ã§èª€ã£ãŠç¿»èš³ãããããã圌ã¯è±èªã§ãªã³ã¯ã瀺ããŸããã
ãã³ãã¬ãŒãã¯10ã§ã¯ãªã8.1ã§èšè¿°ããŠãããããå°ãæ··ä¹±ããŠããŸãã WP 8.1ã®URIçææ¹æ³ã¯ãWindowsã¹ãã¢ã¢ããªã±ãŒã·ã§ã³ã®URIçææ¹æ³ãšãããã«ç°ãªããŸãã WP 8.1ã®å ŽåãURIã¯æ¬¡ã®ããã«ãªããŸãã
ms-windows-storeïŒreviewappïŒappid = cq23k522-7u59-1193-h4aa-3t56e4633c24
å ¬åŒã¬ã€ãïŒãã·ã¢èªïŒïŒ
ã¹ãã¢å ã®ã¢ããªã±ãŒã·ã§ã³ãžã®ãªã³ã¯
è©äŸ¡ãšãŠãŒã¶ãŒãã£ãŒãããã¯ãååŸããããã®éåžžã«è¯ãæ¹æ³ã¯ãäžå®æ°ã®éå§åŸã«ã¢ããªã±ãŒã·ã§ã³ãè©äŸ¡ããããšã§ãã ãŠãŒã¶ãŒãã¢ããªã±ãŒã·ã§ã³ã5åèµ·åãããããã¢ããªã±ãŒã·ã§ã³ã«ã€ããŠäœãèšãããããšããããšæ³å®ããŸãã
ã¢ããªã±ãŒã·ã§ã³ã®èµ·ååæ°ã¯ãã¢ããªã±ãŒã·ã§ã³èšå®ã䜿çšããŠä¿åã§ããŸãã åæã«ãèšå®ãä¿åããæ¹æ³ãèŠã€ããŸãã
èšå®
ã¢ããªã±ãŒã·ã§ã³ãèµ·åãããåæ°ãã«ãŠã³ãã§ããåçŽãªã¹ããããïŒ
å€æ°å®£èšã§ã次ãè¿œå ããŸãã
int appRunCount = 0; Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
this.InitializeComponentïŒïŒã®åŸã®ããŒãžã¯ã©ã¹ã³ã³ã¹ãã©ã¯ã¿ãŒå ã è¿œå ïŒ
try { appRunCount = (int)localSettings.Values["AppRunCount"]; } catch { } appRunCount++; try { localSettings.Values["AppRunCount"] = appRunCount; } catch { }
ãããã£ãŠãappRunCountå€æ°ã«ã¢ããªã±ãŒã·ã§ã³ã®èµ·åæ°ãååŸããŸãã
Windows.Storage.ApplicationData.Current.LocalSettingsã®ä»£ããã«ãWindows.Storage.ApplicationData.Current.RoamingSettingsã䜿çšã§ããŸãã ãããè¡ããšãããŒã«ã«ã§ã¯ãªãããã€ã¹ã«èšå®ãä¿åã§ããŸãããããŒãã³ã°ãã€ãŸã ãããã§ã ãããã¯ãMicrosoftãŠãŒã¶ãŒã¢ã«ãŠã³ãã«ä¿åãããŸãã RoamingSettingsã¯ãåãã¢ã«ãŠã³ããããã°ã€ã³ããŠãããã¹ãŠã®ããã€ã¹ããå©çšã§ããŸãã
5åç®ã®ã¢ããªã±ãŒã·ã§ã³ã®èµ·åæã«ã¡ãã»ãŒãžãçºè¡ãããç°¡åãªã³ãŒãããŠãŒã¶ãŒãè©äŸ¡ãä»ããããšã«åæãããšãã¹ãã¢ãŠã£ã³ããŠãéãããã£ãŒãããã¯ãæ®ãææ¡ã衚瀺ãããŸãã
if (appRunCount == 5) { var messageDialog = new Windows.UI.Popups.MessageDialog(", , ", " !"); // / messageDialog.Commands.Add(new Windows.UI.Popups.UICommand(" ", new Windows.UI.Popups.UICommandInvokedHandler(CommandHandler))); messageDialog.Commands.Add(new Windows.UI.Popups.UICommand(" ", new Windows.UI.Popups.UICommandInvokedHandler(CommandHandler))); messageDialog.Commands.Add(new Windows.UI.Popups.UICommand(" ", new Windows.UI.Popups.UICommandInvokedHandler(CommandHandler))); messageDialog.DefaultCommandIndex = 0; messageDialog.CancelCommandIndex = 2; await messageDialog.ShowAsync(); } private async void CommandHandler(IUICommand command) { if (command.Label==" ") { var uri = new Uri("ms-windows-store:PDP?PFN=9cc1e6dd-9d82-4736-aee5-acb9a01d9c39_1dv79ndb6c382"); await Windows.System.Launcher.LaunchUriAsync(uri); } }
質åããã¯ã¹ã¯æšæºã«èŠããããŸãã«ãæ®éã§ãã çæ³çã«ã¯ãã¢ããªã±ãŒã·ã§ã³ã®èšèšã«é©åããèšèšãæã€ç¬èªã®PopUpãäœæããããšãæåã§ãã ããããããã¯ãã§ã«ãã®èšäºã®ç¯å²å€ã§ãã
èšç®ããã¢ããªã±ãŒã·ã§ã³èšå®ãä¿åããæ¹æ³ã
å ¬åŒã¬ã€ãã®åç §å ã¯æ¬¡ã®ãšããã§ãã
èšå®ãããŠã³ããŒãããŠä¿åãã
ãŠãŒã¶ãŒãModern UIã¢ããªã±ãŒã·ã§ã³ã®äžéšã®èšå®ãå€æŽã§ããããã«ããããã«ãããã©ã€ã¢ãŠãããœã±ãããäœæããããšãã§ããŸã-ãã©ã€ã¢ãŠã
èšå®ãã©ã€ã¢ãŠã
ãã®æ©èœã¯ãWindows 8.1ããã³10ã§ã®ã¿äœ¿çšã§ããŸããWindows8ã§ã¯ãåæ§ã®ãœã±ãããäœæãããå Žåã¯å¯èœã§ãããç¬èªã®ãŠãŒã¶ãŒã³ã³ãããŒã«ãäœæããå¿ èŠããããŸããã
èšå®ãå«ãããã©ã€ã¢ãŠããããã«ãã¢ããªã±ãŒã·ã§ã³ã«è¿œå ããã«ã¯ãSettings FlyoutãšåŒã°ããæ°ããã³ã³ãããŒã«ãè¿œå ããå¿ èŠããããŸãïŒãã·ã¢èªçã®ããã©ã¡ãŒã¿ãŒã®ãããã¢ããèŠçŽ ãïŒã æé ã¯æ¬¡ã®ãšããã§ãã ã¡ãã¥ãŒã«ç§»åããŸãã
ãããžã§ã¯ã-æ°ããã¢ã€ãã ã®è¿œå ...-Visual CïŒ-XAML-èšå®ãã©ã€ã¢ãŠã
ãŸãã¯
ãããžã§ã¯ã-æ°ããã¢ã€ãã ã®è¿œå -ããžã¥ã¢ã«CïŒ-XAML-ãã©ã¡ãŒã¿ãŒãããã¢ãã
ããšãã°ã次ã®ããã«æ°ããèŠçŽ ã«ååãä»ããŸããCustomSettingsFlyout.xaml
App.xaml.csã¢ããªã±ãŒã·ã§ã³ã«åå空éåç §ãè¿œå ããŸãã
using Windows.UI.ApplicationSettings; using Windows.UI.Popups;
ãããŠã次ã®ã³ãŒãïŒ
protected override void OnWindowCreated(WindowCreatedEventArgs args) { SettingsPane.GetForCurrentView().CommandsRequested += OnCommandsRequested; } private void OnCommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args) { SettingsCommand settingsCommand = new SettingsCommand("SettingsPage", "Open settings",new UICommandInvokedHandler(onSettingsCommand)); args.Request.ApplicationCommands.Add(settingsCommand); } private void onSettingsCommand(IUICommand command) { CustomSettingsFlyout settingsFlyout = new CustomSettingsFlyout(); settingsFlyout.Show(); }
ããã§ãã¢ããªã±ãŒã·ã§ã³èšå®ãåŒã³åºããšããŠã£ã³ããŠã衚瀺ãããŸãã å¿ èŠã«å¿ããŠãCustomSettingsFlyoutèŠçŽ ã®XAMLããã³CïŒã³ãŒããç·šéã§ããŸãã
Windows.Storage.ApplicationData.Current.LocalSettingsã¯ã©ã¹ã䜿çšããŠèšå®ãä¿åããæ¹æ³ãåŠç¿ããŸãã
å ¬åŒããã¥ã¢ã«ïŒ
ã¯ã€ãã¯ã¹ã¿ãŒãïŒã¢ããªã±ãŒã·ã§ã³èšå®ã®è¿œå ïŒXAMLïŒ
ãããã¢ããéç¥
ãŠãŒã¶ãŒã«äœããéç¥ããããã«ãããŒã¹ãéç¥ã衚瀺ã§ããŸãã ããã¯ãFlyoutã®ããã«å³åŽã«ãããã¢ããããç»åãšããã¹ããå«ãå°ããªé·æ¹åœ¢ã§ãã MessageBoxãšã¯ç°ãªããããŒã¹ãéç¥ã¯ã¢ããªã±ãŒã·ã§ã³ã€ã³ã¿ãŒãã§ã€ã¹ããããã¯ããŸããã ã³ãŒãå ã§éç¥åŒã³åºããå¥ã®ã¡ãœããã§å²ãŸããŠãããšéåžžã«äŸ¿å©ã§ãã ããã«2ã€ã®åå空éãè¿œå ããŸãã
using Windows.Data.Xml.Dom; using Windows.UI.Notifications;
ãããŠãããã¹ãããã©ã¡ãŒã¿ãšããŠwhichãåŒã³åºããåŸãéç¥ãåãåãã¡ãœããèªäœãè¿œå ããŸãã
void ShowToast(string whattext) { XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01); XmlNodeList stringElements = toastXml.GetElementsByTagName("text"); stringElements[0].AppendChild(toastXml.CreateTextNode(whattext)); ToastNotification toast = new ToastNotification(toastXml); toast.Activated += ToastActivated; toast.Dismissed += ToastDismissed; toast.Failed += ToastFailed; ToastNotificationManager.CreateToastNotifier().Show(toast); }
xmlã«èšå®ããæåã®è¡ã¯ãToastText01ãã³ãã¬ãŒãã§ãã ããã¯ã3è¡ã«ãããããã¹ãã®ã¿ãå«ãéåžžã«åçŽãªãã³ãã¬ãŒãã§ãã
å¯èœãªãã³ãã¬ãŒãã¯ãã¹ãŠããã«ãããŸãïŒ ãããã¢ããéç¥ãã³ãã¬ãŒãã«ã¿ãã°
ãŸããéç¥ã®ã¢ã¯ãã£ãåãéç¥ã®é衚瀺ãããã³éç¥ãšã©ãŒã®3ã€ã®ã€ãã³ãã«ãµãã¹ã¯ã©ã€ãããŠããããšã«ãæ°ã¥ãã§ãããã 次ã«ããããã®ã€ãã³ãã®ãã³ãã©ãŒãå®è£ ããå¿ èŠããããŸãïŒã³ãŒãããªããŠãïŒã
private void ToastFailed(ToastNotification sender, ToastFailedEventArgs args) { } private void ToastDismissed(ToastNotification sender, ToastDismissedEventArgs args) { } private void ToastActivated(ToastNotification sender, object args) { }
å ¬åŒã¬ã€ãïŒ
ã¯ã€ãã¯ã¹ã¿ãŒãã¬ã€ãïŒãããã¢ããéç¥ïŒXAMLïŒãéä¿¡ãã
AppBarããã³CommandBar
æåŸã«ãæšæºã³ã³ãããŒã«ãåããããã«ãã¢ããªã±ãŒã·ã§ã³ã«è¿œå ããŸãã
ããã«ã¯äžéšã§ãäžéšã§ãããŸããŸããã éåžžãã³ãã³ããšããŒã«ã®ãã¿ã³ã¯äžéšããã«ã«é 眮ãããŸãã
次ã®ã¿ã°ã䜿çšããŠãXAMLã§ããã«ãäœæã§ããŸãã
<Page.TopAppBar> <!-- content --> </Page.TopAppBar>
ãŸãã¯
<Page.BottomAppBar> <!-- content --> </Page.BottomAppBar>
ããã«ã®ã³ã³ãã³ãã¯ãAppBarèŠçŽ ïŒææã®äººãé 眮ãããããŸããŸãªã³ã³ãããŒã«çšïŒãŸãã¯CommandBarèŠçŽ ïŒãã¿ã³ã®ã¿-AppBarButtonãAppBarToggleButtonããã³AppBarSeparatorèŠçŽ ã®XAMLïŒã§ãã éåžžã®ã¢ããªã±ãŒã·ã§ã³ã§ã¯ãéåžžã®ãã¿ã³ã§ååãªã®ã§ãCommandBarã«éå®ããŸãã ã³ãŒãã¯æ¬¡ã®ãšããã§ãã
<Page.BottomAppBar> <CommandBar IsOpen="True"> <AppBarButton Label=" Vote and review" Icon="Like" Click="ReviewButton_Click"/> <AppBarButton x:Name="btnSecTile" Label="Add to Start" Click="btnSecTile_Click" Icon="Pin"/> <CommandBar.SecondaryCommands> <AppBarButton Label="Share" Icon="OtherUser" Click="ShareButton_Click"/> </CommandBar.SecondaryCommands> </CommandBar> </Page.BottomAppBar>
IsOpen =â Trueâå±æ§ã«æ³šæããŠãã ããã ã¢ããªã±ãŒã·ã§ã³ãéããšãããŠãŒã¶ãŒããã®å¯çšæ§ãèªèããããã«å¿ããŠã¢ããªã±ãŒã·ã§ã³ã«ã©ããªæ©äŒãããããç¥ãããã«ããã«ã衚瀺ããããšãæãŸããã§ãã ãŸããå·Šããã«ã«åæ ããããã¿ã³ãå«ããã¹ããããã¿ã°CommandBar.SecondaryCommandsã«æ°ä»ãããšãã§ããŸãã ãããã¯äºæ¬¡çãªãã®ã§ãã
å ¬åŒã¬ã€ãïŒ
ã¯ã€ãã¯ã¹ã¿ãŒãã¬ã€ãïŒã¢ããªã±ãŒã·ã§ã³ããã«ã®è¿œå ïŒXAMLïŒ
äºæ¬¡ã¿ã€ã«
ãŠãŒã¶ãŒãè£å©ã¿ã€ã«/ã¿ã€ã«ãWindowsã¹ã¿ãŒãç»é¢ã«ä¿®æ£ã§ããããã«ããããšãå¯èœã§ãã ãã®ã¿ã€ã«ãã¯ãªãã¯ãããšãç¹å®ã®ãã©ã¡ãŒã¿ãŒã§ã¢ããªã±ãŒã·ã§ã³ãéãããšãã§ããè£å©ã¿ã€ã«ããã©ã€ããïŒã€ãŸããã©ã€ãã¿ã€ã«ïŒã«ããŠç¹å¥ãªã¢ã©ãŒãã衚瀺ã§ããŸãã
ãŸããã»ã«ã³ããªã¿ã€ã«ãè¿œå ããããã«ãå¿ èŠãªæ¬ èœããŠããåå空éãè¿œå ããŸãã
using Windows.UI.StartScreen;
InitializeComponentïŒïŒã®åŸã®ããŒãžã³ã³ã¹ãã©ã¯ã¿ãŒã ãã©ã¡ãŒã¿ã䜿çšããŠã¡ãœããåŒã³åºããè¿œå ããŸãã
ToggleAppBarButton(!SecondaryTile.Exists("MyUnicTileID"));
ããã§ãMyUnicTileIDã¯ã¿ã€ã«ã®äžæã®èå¥åã§ã
次ã«ãToggleAppBarButtonã¡ãœããèªäœãè¿œå ããå¿ èŠããããŸãããã®ã¡ãœããã¯ãè£å©ã¿ã€ã«ã®çŸåšã®ç¶æ ã«å¿ããŠãã¢ã¿ããã¢ã€ã³ã³ãŸãã¯ãã¿ããã¢ã€ã³ã³ã衚瀺ããŸãã
public void ToggleAppBarButton(bool showPinButton) { if (showPinButton) { btnSecTile.Label = ""; btnSecTile.Icon = new SymbolIcon(Symbol.Pin); } else { btnSecTile.Label = ""; btnSecTile.Icon = new SymbolIcon(Symbol.UnPin); } this.btnSecTile.UpdateLayout(); }
ããã§ãshowPinButtonã¯æž¡ãããå€ãä¿åããããŒã«å€æ°ã§ãïŒSecondaryTile.ExistsïŒ "MyUnicTileID"ïŒãã€ãŸã ã¢ããªã±ãŒã·ã§ã³ã®è£å©ã¿ã€ã«ãéå§ç»é¢ã«æ·»ä»ãããŠãããã©ããã
次ã«ããã¿ã³ã¯ãªãã¯ã€ãã³ãã«ã³ãŒããè¿œå ããŸãã ãã®ã³ãŒãã¯ãã¿ã€ã«ãåæç»é¢ã«æ·»ä»ããããåºå®ã解é€ããŸãã
private async void btnSecTile_Click(object sender, RoutedEventArgs e) { Windows.Foundation.Rect rect = GetElementRect((FrameworkElement)sender); if (SecondaryTile.Exists("MyUnicTileID")) { SecondaryTile secondaryTile = new SecondaryTile("MyUnicTileID"); bool isUnpinned = await secondaryTile.RequestDeleteForSelectionAsync(rect, Windows.UI.Popups.Placement.Above); ToggleAppBarButton(isUnpinned); } else { // Pin Uri square150x150Logo = new Uri("ms-appx:///Assets/Logo.scale-100.png"); string tileActivationArguments = "Secondary tile was pinned at = " + DateTime.Now.ToLocalTime().ToString(); string displayName = "Application name"; TileSize newTileDesiredSize = TileSize.Square150x150; SecondaryTile secondaryTile = new SecondaryTile("MyUnicTileID", displayName, tileActivationArguments, square150x150Logo, newTileDesiredSize); secondaryTile.VisualElements.Square30x30Logo = new Uri("ms-appx:///Assets/SmallLogo.scale-100.png"); secondaryTile.VisualElements.ShowNameOnSquare150x150Logo = true; secondaryTile.VisualElements.ForegroundText = ForegroundText.Light; bool isPinned = await secondaryTile.RequestCreateForSelectionAsync(rect, Windows.UI.Popups.Placement.Above); ToggleAppBarButton(!isPinned); } }
ãŸããé¢æ°ãè¿œå ããå¿ èŠããããŸã
public static Rect GetElementRect(FrameworkElement element) { GeneralTransform buttonTransform = element.TransformToVisual(null); Point point = buttonTransform.TransformPoint(new Point()); return new Rect(point, new Size(element.ActualWidth, element.ActualHeight)); }
ã¿ã€ã«ãåæç»é¢ã«ä¿®æ£ãããšã次ã®ãããªèŠåã衚瀺ãããŸãã
ãApp Templateãã¯ãã¢ããªã±ãŒã·ã§ã³ã®ååã§ãã ã¿ã€ã«ãä¿®æ£ããããã¢ããªã±ãŒã·ã§ã³ã®ç©ºãé åã®ã©ãããã¯ãªãã¯ããŠãããã¢ãããéããããšã«ããæåŠã§ããŸãã
ãã€ãã®ããã«ãå ¬åŒã¬ã€ããžã®ãªã³ã¯ïŒ
ã¯ã€ãã¯ã¹ã¿ãŒãã¬ã€ãã è£å©ã¿ã€ã«ã®ä¿®æ£ïŒXAMLïŒ
ãããã¯ãWindowsã¹ãã¢ã¢ããªã®æ©èœã®äžéšã§ããã ãããã䜿çšããããšã匷ããå§ãããŸãã
GitHubã®ãªã³ã¯ããçµæã®ãã³ãã¬ãŒããããŠã³ããŒãã§ããŸãã
https://github.com/programmersommer/WindowsStoreAppTemplate
ãŸãã¯zipã¢ãŒã«ã€ããšããŠïŒãã·ã¢èªã®ã³ã¡ã³ãä»ãããŒãžã§ã³ïŒïŒ
OneDrive