if (SecondaryTile.Exists(appbarTileId)) { SecondaryTile secondaryTile = new SecondaryTile(appbarTileId); bool isUnpinned = await secondaryTile.RequestDeleteForSelectionAsync(GetElementRect((FrameworkElement)sender), Windows.UI.Popups.Placement.Above); } else { Uri logo = new Uri("ms-appx:///images/150.png"); string tileActivationArguments = appbarTileId + " was pinned at " + DateTime.Now.ToLocalTime().ToString(); SecondaryTile secondaryTile = new SecondaryTile(appbarTileId, "how do you think?", "what it is?", tileActivationArguments, TileOptions.ShowNameOnLogo, logo); secondaryTile.ForegroundText = ForegroundText.Dark; secondaryTile.SmallLogo = new Uri("ms-appx:///images/150.png"); bool isPinned = await secondaryTile.RequestCreateForSelectionAsync(GetElementRect((FrameworkElement)sender), Windows.UI.Popups.Placement.Above); } private Rect GetElementRect(FrameworkElement frameworkElement) { GeneralTransform buttonTransform = frameworkElement.TransformToVisual(null); Point point = buttonTransform.TransformPoint(new Point()); return new Rect(point, new Size(frameworkElement.ActualWidth, frameworkElement.ActualHeight)); }
参考链接:http://msdn.microsoft.com/zh-CN/library/windows/apps/xaml/Hh868249(v=win.10).aspx