/// <summary> /// Sample Merged tiles with images and text /// </summary> /// <param name="updater"></param> public static void UpdateTileWithWideTextImage(NotificationTile notificationTile) { if (notificationTile != null) { TileUpdateManager.CreateTileUpdaterForApplication().EnableNotificationQueue(false); TileUpdateManager.CreateTileUpdaterForApplication().Clear(); var photoTileSmall = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquarePeekImageAndText02); var photoTileWide = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWideImageAndText01); //Add several tile templates to an IEnumerable<> list for merging string TextBodyWrap = string.Empty; if (notificationTile.TextBodyWrap.Length > 80) { TextBodyWrap = notificationTile.TextBodyWrap.Substring(0, 80); } else { TextBodyWrap = notificationTile.TextBodyWrap; } var liveTilesIn = new List <XmlDocument> { photoTileSmall.AddImages(new[] { notificationTile.ImageUri }, new[] { notificationTile.ImageAltName }).AddText(new[] { TextBodyWrap }), photoTileWide.AddImages(new[] { notificationTile.ImageUri }, new[] { notificationTile.ImageAltName }).AddText(new[] { TextBodyWrap }) }; //Use the Tag property to uniquely identify this tile TileNotification tileNotification = new TileNotification(liveTilesIn.MergeTiles()); if (!string.IsNullOrEmpty(notificationTile.NotificationTileTag) || !string.IsNullOrWhiteSpace(notificationTile.NotificationTileTag)) { tileNotification.Tag = notificationTile.NotificationTileTag; } TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification); } }
private static void UpdateSecondaryTileWithImage(string tileId, NotificationTile notificationTile, NotificationSecondaryTileType tileType) { if (!string.IsNullOrEmpty(tileId) && !string.IsNullOrWhiteSpace(tileId) && notificationTile != null) { TileUpdateManager.CreateTileUpdaterForSecondaryTile(tileId).EnableNotificationQueue(false); TileUpdateManager.CreateTileUpdaterForSecondaryTile(tileId).Clear(); ITileSquarePeekImageAndText02 squareImageAndTextContent = TileContentFactory.CreateTileSquarePeekImageAndText02(); squareImageAndTextContent.Image.Src = notificationTile.ImageUri; squareImageAndTextContent.Image.Alt = notificationTile.ImageAltName; squareImageAndTextContent.TextHeading.Text = notificationTile.TextHeading; squareImageAndTextContent.TextBodyWrap.Text = notificationTile.TextBodyWrap; if (tileType == NotificationSecondaryTileType.CustomTile) { ITileWideImageAndText01 tileContent = TileContentFactory.CreateTileWideImageAndText01(); tileContent.Image.Src = notificationTile.ImageUri; tileContent.Image.Alt = notificationTile.ImageAltName; tileContent.TextCaptionWrap.Text = notificationTile.TextBodyWrap; tileContent.SquareContent = squareImageAndTextContent; TileUpdateManager.CreateTileUpdaterForSecondaryTile(tileId).Update(tileContent.CreateNotification()); } else { ITileWidePeekImage05 tileContent = TileContentFactory.CreateTileWidePeekImage05(); tileContent.ImageMain.Src = tileContent.ImageSecondary.Src = notificationTile.ImageUri; tileContent.ImageMain.Alt = tileContent.ImageSecondary.Alt = notificationTile.ImageAltName; tileContent.TextHeading.Text = notificationTile.TextHeading; tileContent.TextBodyWrap.Text = notificationTile.TextBodyWrap; tileContent.SquareContent = squareImageAndTextContent; TileUpdateManager.CreateTileUpdaterForSecondaryTile(tileId).Update(tileContent.CreateNotification()); } } }
public async static Task <bool> PinSecondaryTileWithImage(string tileId, NotificationTile notificationTile, NotificationSecondaryTileType tileType = NotificationSecondaryTileType.DefaultTile, FrameworkElement element = null) { bool isPin = false; if (!string.IsNullOrEmpty(tileId) && !string.IsNullOrWhiteSpace(tileId)) { if (CheckSecondaryTileExist(tileId)) { isPin = true; } else { var isCreateSecondaryTile = await CreateSecondaryTile(tileId, notificationTile, element); if (isCreateSecondaryTile) { UpdateSecondaryTileWithImage(tileId, notificationTile, tileType); isPin = true; } else { SecondaryTile secondaryTile = new SecondaryTile(tileId); await secondaryTile.RequestDeleteAsync(); } } } return(isPin); }
/// <summary> /// /// </summary> /// <param name="notificationTile"></param> public static void UpdateTileWithImage(NotificationTile notificationTile) { if (notificationTile != null) { TileUpdateManager.CreateTileUpdaterForApplication().EnableNotificationQueue(false); TileUpdateManager.CreateTileUpdaterForApplication().Clear(); ITileWideImageAndText01 tileContent = TileContentFactory.CreateTileWideImageAndText01(); tileContent.Image.Src = notificationTile.ImageUri; tileContent.Image.Alt = notificationTile.ImageAltName; if (notificationTile.TextBodyWrap.Length > 80) { tileContent.TextCaptionWrap.Text = notificationTile.TextBodyWrap.Substring(0, 80); } else { tileContent.TextCaptionWrap.Text = notificationTile.TextBodyWrap; } ITileSquarePeekImageAndText02 squareImageAndTextContent = TileContentFactory.CreateTileSquarePeekImageAndText02(); squareImageAndTextContent.Image.Src = notificationTile.ImageUri; squareImageAndTextContent.Image.Alt = notificationTile.ImageAltName; if (notificationTile.TextHeading.Length > 30) { squareImageAndTextContent.TextHeading.Text = notificationTile.TextHeading.Substring(0, 30); } else { squareImageAndTextContent.TextHeading.Text = notificationTile.TextHeading; } if (notificationTile.TextBodyWrap.Length > 80) { squareImageAndTextContent.TextBodyWrap.Text = notificationTile.TextBodyWrap.Substring(0, 80); } else { squareImageAndTextContent.TextBodyWrap.Text = notificationTile.TextBodyWrap; } tileContent.SquareContent = squareImageAndTextContent; TileUpdateManager.CreateTileUpdaterForApplication().Update(tileContent.CreateNotification()); } }
/// <summary> /// Sample Merged Tiles text only /// </summary> /// <param name="updater"></param> public static void UpdateTileWithText(NotificationTile notificationTile) { if (notificationTile != null) { TileUpdateManager.CreateTileUpdaterForApplication().EnableNotificationQueue(false); TileUpdateManager.CreateTileUpdaterForApplication().Clear(); var statusTile = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquareText02); string TextHeading = string.Empty; if (notificationTile.TextHeading.Length > 30) { TextHeading = notificationTile.TextHeading.Substring(0, 30); } else { TextHeading = notificationTile.TextHeading; } string TextBodyWrap = string.Empty; if (notificationTile.TextBodyWrap.Length > 80) { TextBodyWrap = notificationTile.TextBodyWrap.Substring(0, 80); } else { TextBodyWrap = notificationTile.TextBodyWrap; } TileNotification tileNotification = new TileNotification(statusTile.AddText(new[] { TextHeading, TextBodyWrap })); if (!string.IsNullOrEmpty(notificationTile.NotificationTileTag) || !string.IsNullOrWhiteSpace(notificationTile.NotificationTileTag)) { tileNotification.Tag = notificationTile.NotificationTileTag; } TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification); } }
private async static Task <bool> CreateSecondaryTile(string tileId, NotificationTile notificationTile, FrameworkElement element) { //Uri logo = new Uri("ms-appx:///Assets/blue_squ.png"); Uri logo = null; Uri wideLogo = null; bool fetchHead = false; bool result = false; string shortName = string.Empty; string displayName = string.Empty; string arguments = string.Empty; try { if (notificationTile != null) { //var uri = await new UriDownloader().Download(notificationTile.ImageUri, notificationTile.ImageUri.ComputeMD5(), SecondaryTileFolder); var uri = await new UriDownloader().Download(notificationTile.ImageUri, tileId.ComputeMD5(), SecondaryTileFolder); if (uri != null) { logo = uri; wideLogo = uri; shortName = notificationTile.TextHeading; displayName = notificationTile.TextHeading; fetchHead = true; } } } catch (Exception ex) { Debug.WriteLine(ex.Message); fetchHead = false; } if (!fetchHead) { logo = new Uri("ms-appx:///Assets/Logo.png"); wideLogo = new Uri("ms-appx:///Assets/WideLogo.png"); shortName = "YouTube Secondary Tile"; displayName = "YouTube Secondary Tile"; } arguments = tileId + DateTime.Now.ToLocalTime().ToString(); // Create a Secondary tile SecondaryTile secondaryTile = new SecondaryTile(tileId, shortName, displayName, arguments, TileOptions.ShowNameOnLogo | TileOptions.ShowNameOnWideLogo, logo, wideLogo); secondaryTile.ForegroundText = ForegroundText.Light; if (element != null) { result = await secondaryTile.RequestCreateForSelectionAsync( GetElementRect((FrameworkElement)element), Windows.UI.Popups.Placement.Below); } else { result = await secondaryTile.RequestCreateAsync(); } return(result); }