Frage

I have a basic RSS reader that displays the list of Blog posts in a listView in the left Grid.Column. In the Right Grid.Column is the WebView. When the user selects an item in the listView, the Webview is updated with Uri and displays the web page.

Now, I've added a BottomAppBar and created Pin/UnPin buttons. I've successfully created the pinning ability, however, I am not passing any data into the NavigationContext's query string. 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. I've done this dozens of time in my Windows Phone apps, but I'm stuck here for this Windows 8 app. On WP7, I am using a context menu to pin the item. 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)

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:

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!! Safe casting to your ItemViewModel items does the trick.

var item = itemListView.SelectedItem as FeedItems (or your ItemViewModel items);
War es hilfreich?

Lösung

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. This will let you access all of the properties, including Uri, on the selected item. If selectedItem is null after this call, you are not casting to the right 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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top