Example #1
0
        internal async Task<bool> PinAsync(DetailPageViewModel detailPageViewModel)
        {
            var name = "Tiles sample";
            var title = "Template 10";
            var body = detailPageViewModel.Value;
            var image = "https://raw.githubusercontent.com/Windows-XAML/Template10/master/Assets/Template10.png";

            var bindingContent = new TileBindingContentAdaptive()
            {
                PeekImage = new TilePeekImage()
                {
                    Source = new TileImageSource(image)
                },

                Children =
                {
                    new TileText()
                    {
                        Text = title,
                        Style = TileTextStyle.Body
                    },

                    new TileText()
                    {
                        Text = body,
                        Wrap = true,
                        Style = TileTextStyle.CaptionSubtle
                    }
                }
            };

            var binding = new TileBinding()
            {
                Branding = TileBranding.NameAndLogo,
                DisplayName = name,
                Content = bindingContent
            };

            var content = new TileContent()
            {
                Visual = new TileVisual()
                {
                    TileMedium = binding,
                    TileWide = binding,
                    TileLarge = binding
                }
            };

            var xml = content.GetXml();

            // show tile

            var tileId = detailPageViewModel.ToString();

            if (!await IsPinned(detailPageViewModel))
            {
                // initial pin
                var logo = new Uri("ms-appx:///Assets/Logo.png");
                var secondaryTile = new SecondaryTile(tileId)
                {
                    Arguments = detailPageViewModel.Value,
                    DisplayName = name,
                    VisualElements =
                        {
                            Square44x44Logo = logo,
                            Square150x150Logo = logo,
                            Wide310x150Logo = logo,
                            Square310x310Logo = logo,
                            ShowNameOnSquare150x150Logo = true,
                        },
                };
                if (!await secondaryTile.RequestCreateAsync())
                {
                    System.Diagnostics.Debugger.Break();
                    return false;
                }
            }

            // add notifications

            var tileNotification = new TileNotification(xml);
            var tileUpdater = TileUpdateManager.CreateTileUpdaterForSecondaryTile(tileId);
            tileUpdater.Update(tileNotification);

            // show toast

            ShowToast(detailPageViewModel);

            // result

            return true;
        }
Example #2
0
 internal async Task<bool> IsPinned(DetailPageViewModel detailPageViewModel)
 {
     var tileId = detailPageViewModel.ToString();
     return (await SecondaryTile.FindAllAsync()).Any(x => x.TileId.Equals(tileId));
 }
Example #3
0
        void ShowToast(DetailPageViewModel detailPageViewModel)
        {
            var data = detailPageViewModel.Value;
            var image = "https://raw.githubusercontent.com/Windows-XAML/Template10/master/Assets/Template10.png";

            var content = new ToastContent()
            {
                Launch = data,
                Visual = new ToastVisual()
                {
                    TitleText = new ToastText()
                    {
                        Text = "Secondary tile pinned"
                    },

                    BodyTextLine1 = new ToastText()
                    {
                        Text = detailPageViewModel.Value
                    },

                    AppLogoOverride = new ToastAppLogo()
                    {
                        Crop = ToastImageCrop.Circle,
                        Source = new ToastImageSource(image)
                    }
                },
                Audio = new ToastAudio()
                {
                    Src = new Uri("ms-winsoundevent:Notification.IM")
                }
            };

            var notification = new ToastNotification(content.GetXml());
            var notifier = ToastNotificationManager.CreateToastNotifier();
            notifier.Show(notification);
        }
Example #4
0
 internal async Task<bool> UnPinAsync(DetailPageViewModel detailPageViewModel)
 {
     if (!await IsPinned(detailPageViewModel))
         return true;
     try
     {
         var tileId = detailPageViewModel.ToString();
         var tile = new SecondaryTile(tileId);
         return await tile.RequestDeleteAsync();
     }
     catch (Exception)
     {
         System.Diagnostics.Debugger.Break();
         return false;
     }
 }
Example #5
0
        internal async Task<bool> PinAsync(DetailPageViewModel detailPageViewModel)
        {
            // prepare content

            var header = new Text("Template 10")
            {
                Style = TextStyle.Subtitle
            };

            var content = new Text(detailPageViewModel.Value)
            {
                Style = TextStyle.Caption,
                WrapText = true
            };

            var logo = new TileImage(ImagePlacement.Inline)
            {
                Source = "https://raw.githubusercontent.com/Windows-XAML/Template10/master/Assets/Template10.png"
            };

            // build tile

            var tile = AdaptiveTile.CreateTile(string.Empty);
            var binding = TileBinding.Create(TemplateType.TileWide);
            binding.Branding = Branding.Name;

            var sub1 = new SubGroup { Width = 33 };
            binding.Add(sub1);
            sub1.AddImage(logo);

            var sub2 = new SubGroup();
            binding.Add(sub2);
            sub2.AddText(header);
            sub2.AddText(content);

            tile.Tiles.Add(binding);

            // show tile

            var tileId = detailPageViewModel.ToString();

            if (!await IsPinned(detailPageViewModel))
            {
                // initial pin
                var secondaryTile = new SecondaryTile(tileId)
                {
                    Arguments = detailPageViewModel.Value,
                    DisplayName = "Detail page",
                    VisualElements =
                        {
                            Square44x44Logo = new Uri("ms-appx:///Assets/Logo.png"),
                            Square150x150Logo = new Uri("ms-appx:///Assets/Logo.png"),
                            Wide310x150Logo = new Uri("ms-appx:///Assets/Logo.png"),
                            Square310x310Logo = new Uri("ms-appx:///Assets/Logo.png"),
                            ShowNameOnSquare150x150Logo = true,
                        },
                };
                if (!await secondaryTile.RequestCreateAsync())
                {
                    System.Diagnostics.Debugger.Break();
                    return false;
                }
            }

            // update pin
            var xml = tile.GetNotification().Content;
            xml.DocumentElement.RemoveAttribute("version");
            var value = xml.GetXml();
            var tileUpdater = TileUpdateManager.CreateTileUpdaterForSecondaryTile(tileId);
            var tileNotification = new TileNotification(xml);
            tileUpdater.Update(tileNotification);

            return true;
        }