我在另一个页面中显示一个列表,当点击一个列表项时,控件转移到另一个页面,在那里我点击了数据。
我可以使用pin appbar按钮将一个事件的辅助磁贴固定为启动面板。
显示页面已固定。
现在,我想为每个点击的列表视图项目添加新的图块。
我可以在列表中获取所选项目的ID。
那么是否有可能检查每个id,pinbar是否被激活..?
这里是我写的代码: -
private void ToggleAppBarButton(bool showPinButton)
{
if (showPinButton)
{
this.PinUnPinCommandButton.Label = "Pin to start";
this.PinUnPinCommandButton.Icon = new SymbolIcon(Symbol.Pin);
}
else
{
this.PinUnPinCommandButton.Label = "Unpin from start";
this.PinUnPinCommandButton.Icon = new SymbolIcon(Symbol.UnPin);
}
this.PinUnPinCommandButton.UpdateLayout();
}
void Init()
{
ToggleAppBarButton(!SecondaryTile.Exists(EditWindow.appbarTileId));
this.PinUnPinCommandButton.Click += this.pinToAppBar_Click;
}
async void pinToAppBar_Click(object sender, RoutedEventArgs e)
{
this.SecondTileCommmandbar.IsSticky = true;
if (SecondaryTile.Exists(EditWindow.appbarTileId))
{
SecondaryTile secondarytile = new SecondaryTile(EditWindow.appbarTileId);
bool ispinned = await secondarytile.RequestDeleteForSelectionAsync(EditWindow.GetElementRect((FrameworkElement)sender), Windows.UI.Popups.Placement.Above);
ToggleAppBarButton(ispinned);
}
else
{
Uri square150x150Logo = new Uri("ms-appx:///Assets/SmallScreen.scale-140.png");
string tileActivationArguments = EditWindow.appbarTileId + " WasPinnedAt=" + DateTime.Now.ToLocalTime().ToString();
string displayName = daysleft.Events = event_text.Text;
SecondaryTile secondaryTile = new SecondaryTile(EditWindow.appbarTileId,
displayName,
tileActivationArguments,
new Uri("ms-appx:///Assets/Square71x71Logo.scale-140.png"), TileSize.Square150x150);
secondaryTile.VisualElements.ShowNameOnSquare150x150Logo = true;
await secondaryTile.RequestCreateAsync();
}
this.BottomAppBar.IsSticky = false;
}
void BottomAppBar_Opened(object sender, object e)
{
ToggleAppBarButton(!SecondaryTile.Exists(EditWindow.appbarTileId));
}
private static 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));
}
private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
//accesing clicked listview item from different page
Selected_DaysId = Int32.Parse(e.Parameter.ToString());
Debug.WriteLine("Selected_DaysId "+Selected_DaysId);
//Method to initialize the pin appbar
Init();
}
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
base.OnNavigatingFrom(e);
if (e.NavigationMode == NavigationMode.Back)
{
ResetPageCache();
}
}
private void ResetPageCache()
{
var cacheSize = ((Frame)Parent).CacheSize;
((Frame)Parent).CacheSize = 0;
((Frame)Parent).CacheSize = cacheSize;
}
答案 0 :(得分:1)
根据我的理解,您希望查找特定ID是否已固定。
bool isPinned = await secondaryTile.RequestCreateAsync();
如果已固定磁贴,则返回false值,您可以使用最初创建它的相同ID创建新的辅助磁贴,并检查ispinned值是true还是false。通过这种方式,您将知道您的瓷砖是否固定。
修改强> 讨论后的代码解决方案
if (SecondaryTile.Exists(Selected_DaysId.ToString()))
{
var secondaryTile = new SecondaryTile(
Selected_DaysId.ToString(),
"Text shown on tile",
"secondTileArguments",
new Uri("ms-appx:///Assets/image.jpg", UriKind.Absolute),
TileSize.Square150x150);
bool isPinned1 = await secondaryTile.RequestDeleteAsync();
}