3
votes

I've displaying a list in another page, when a listitem is clicked the control transferred to another page where I was pin that clicked data.

I can pin the the secondary tile for one event to start panel using pin appbar button .

It is showing that the page is already pinned.

Now, I would like pin new tiles for each clicked listview item.

I can get the id of the selected item in a list.

So Is it possible to check for each id that,whether the pinbar is activated or not..?

Here the code which I have written :-

     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;
    }
1

1 Answers

1
votes

From what I understood, you want to find if a particular ID was already pinned or not.

bool isPinned = await secondaryTile.RequestCreateAsync();

this returns a false value if the tile is already pinned you can create a new secondary tile using the same ID with which you would create it initially and check if ispinned value is true or false. this way you will know if your tile was pinned or not.

EDIT After Discussion code solution reached

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(); 
}