如何在 Windows Phone 8.1 中为每个列表视图单击的项目固定辅助磁贴 [英] How to pin a secondary tiles for each listview clicked item in windows phone 8.1

查看:21
本文介绍了如何在 Windows Phone 8.1 中为每个列表视图单击的项目固定辅助磁贴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在另一个页面中显示了一个列表,当单击一个列表项时,控件会转移到另一个页面,我在该页面上固定了单击的数据.

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.

我可以使用 pin appbar button 将一个事件的辅助磁贴固定到启动面板.

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

显示页面已固定.

现在,我想为每个点击的列表视图项目固定新图块.

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

我可以在列表中获取所选项目的 id.

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

那么是否可以检查每个 id,pinbar 是否被激活..?

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

推荐答案

据我所知,您想知道某个特定 ID 是否已被固定.

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

bool isPinned = await secondaryTile.RequestCreateAsync();

如果磁贴已被固定,这将返回一个错误值,您可以使用与最初创建它时使用的 ID 相同的 ID 创建一个新的辅助磁贴,并检查 ispinned 值是真还是假.这样您就可以知道您的磁贴是否已固定.

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.

编辑讨论代码解决方案后

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

这篇关于如何在 Windows Phone 8.1 中为每个列表视图单击的项目固定辅助磁贴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆