简体   繁体   English

当用户从BottomAppBar固定时,如何确定选择了哪个ListView项目及其Url

[英]How do I determine which ListView item, and it's Url, was selected when the user pins from the BottomAppBar

I have a basic RSS reader that displays the list of Blog posts in a listView in the left Grid.Column. 我有一个基本的RSS阅读器,它在左侧Grid.Column的listView中显示Blog帖子的列表。 In the Right Grid.Column is the WebView. 在右边的Grid.Column中是WebView。 When the user selects an item in the listView, the Webview is updated with Uri and displays the web page. 当用户在listView中选择一个项目时,Web视图将用Uri更新并显示该网页。

Now, I've added a BottomAppBar and created Pin/UnPin buttons. 现在,我添加了一个BottomAppBar并创建了Pin / UnPin按钮。 I've successfully created the pinning ability, however, I am not passing any data into the NavigationContext's query string. 我已经成功创建了固定功能,但是,我没有将任何数据传递到NavigationContext的查询字符串中。 So when the user clicks on the pinned tile, it only deeplinks to the overall page and not the selected article. 因此,当用户单击固定的图块时,它只会深度链接到整个页面,而不是所选文章。 This loads all the latest articles and not the selected item's url. 这将加载所有最新文章,而不是所选项目的网址。

I know I have to pass the Url into the pinned tile's querystring, but I'm stuck here. 我知道我必须将Url传递到固定图块的querystring中,但是我被困在这里。 I've done this dozens of time in my Windows Phone apps, but I'm stuck here for this Windows 8 app. 我已经在Windows Phone应用程序中完成了数十次操作,但对于此Windows 8应用程序却停留在这里。 On WP7, I am using a context menu to pin the item. 在WP7上,我使用上下文菜单固定该项目。 Here I am pinning from the appbar and I can't seem to get the url and add it as a querystring (As my TileActivationArgument) 在这里,我是固定在应用栏中的,似乎无法获取该网址并将其添加为查询字符串(作为我的TileActivationArgument)

Mainly I need guidance with how to get the selected item's data and get it onto the tile and how to read it coming back in. Here is my Pin() method: 我主要需要有关如何获取所选项目的数据并将其获取到图块上以及如何读取返回的指导。这是我的Pin()方法:

EDIT: I've gone ahead and made a temporary working solution, but it doesn't solve my issue of not being able to retrieve the selected item's properties. 编辑:我已经前进并提出了一个临时的工作解决方案,但它不能解决我无法检索所选项目的属性的问题。 Comments are inline w/the code 注释内联代码

private async void PinTileHelper(string message, object sender)
    {
        //This is my preferred method, but I cannot extract the SelectedItem's properties
        //var item = itemListView.SelectedItem;


        //I'm not able to use the sender because this is a button click
        //var selectedItem = (FeedItems)((ListView)sender).SelectedItem;

        //As a cheesy workaround, I just took the Uri directly from the WebView's source Uri
        var ActivationArgument = this.ContentView.Source.ToString();

        Uri logo = new Uri("ms-appx:///Assets/squareTile-sdk.png");
        //Uri smallLogo = new Uri("ms-appx:///Assets/smallTile-sdk.png");

        SecondaryTile secondaryTile = new SecondaryTile("Toolbox",
                                                        "Fantasy Football Tile",
                                                        "Article name goes here and ",
                                                        ActivationArgument,
                                                        TileOptions.ShowNameOnLogo,
                                                        logo);

        secondaryTile.ForegroundText = ForegroundText.Dark;
        //secondaryTile.SmallLogo = smallLogo;

        bool isPinned = await secondaryTile.RequestCreateAsync();

        MessageDialog dialog = new MessageDialog("Pinned?");

        if (isPinned)
        {
            dialog.Content = "You have succesfully pinned this tile";
            await dialog.ShowAsync();
        }
        else
        {
            dialog.Content = "Something went wrong. The tile wasn't pinned.";
            await dialog.ShowAsync();
        }
    }

Thanks for any insight you can provide. 感谢您提供的任何见解。

EDIT #2: Success!! 编辑#2:成功! Safe casting to your ItemViewModel items does the trick. 安全地投射到ItemViewModel项可以解决问题。

var item = itemListView.SelectedItem as FeedItems (or your ItemViewModel items);

Try replacing 尝试更换

var selectedItem = (FeedItems)((ListView)sender).SelectedItem;

with

var selectedItem = (FeedItems)((ListView)sender).SelectedItem as FeedItem;

I'm assuming that is the correct class Type for the as statement. 我假设这是as语句的正确类Type。 This will let you access all of the properties, including Uri, on the selected item. 这使您可以访问所选项目上的所有属性,包括Uri。 If selectedItem is null after this call, you are not casting to the right Type. 如果在此调用之后selectedItem为null,则您没有转换为正确的Type。 Cast to the appropriate class type. 强制转换为适当的类类型。 Right now, with the code as is, you are getting a plain old object back. 现在,按原样使用代码,您将获得一个普通的旧对象。

Yes, you grab the LaunchArgs and pass them on to your destination page as part of handling your start navigation. 是的,您可以获取LaunchArgs并将其传递到目标页面,这是处理开始导航的一部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在组合框中,如何确定突出显示的项目(未选择项目)? - In a combobox, how do I determine the highlighted item (not selected item)? 我怎么知道在列表视图+图像列表中选择了哪个项目 - how can I know which Item was selected in listview + imagelist 如何将列表视图中包含的选定图像的URL从一个aspx页面传递到另一页面? - How can I pass the url of a selected image which is included in a listview from one aspx page to another? 如何在C#中使用Caliburn.Micro从ListView获取选定的项目和事件? - How can i get selected item(s) and events from ListView with Caliburn.Micro in C#? 如何从wpf的listview中获取未选择的项目 - How to get a not selected item from wpf's listview 如何更改 ListView 上所选项目的颜色? - How do I change the color of a selected item on a ListView? 如何通过打开上下文操作菜单从ListView中获取所选项目? (Xamarin.Forms) - How do I get the selected item from a ListView by opening the context actions menu? (Xamarin.Forms) 如何获取图像ListView中所选项目的索引? - How do I get the index of a selected item in an image ListView? 如何在ListView(XAML)中更改所选项目的前景色 - How do I change the forground color on selected item in a ListView (XAML) 在C#中,如何突出显示列表视图中的选定项目? - In C#, how do I highlight selected item in a listview?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM