

#Microsoft toolkit download reddit update#
This will be a much simpler viewmodel, as it really only needs to expose a Post property with the currently selected post, and to receive broadcast messages from the subreddit widget to update the Post property. Now let's take a look at what we need for viewmodel of the post widget. / Loads the posts from a specified subreddit. Set => SetProperty(ref selectedPost, value, true) Set => SetProperty(ref selectedSubreddit, value) / Gets or sets the currently selected subreddit. Public IAsyncRela圜ommand LoadPostsCommand = new / Gets the instance responsible for loading posts. LoadPostsCommand = new AsyncRela圜ommand(LoadPostsAsync) Here's the viewmodel so far: public sealed class SubredditWidgetViewModel : ObservableRecipient Methods: we just need a private LoadPostsAsync method which will be wrapped by our async command, and which will contain the logic to load posts from the selected subreddit.This is done to be able to notify the post widget that the current post selection is changed. In this case we're using the SetProperty method from the ObservableRecipient class to indicate that we also want to broadcast notifications when this property changes. object SelectedPost, which is the currently selected post.Here we're using the SetProperty method from the ObservableObject class. This property needs to be bound to the UI, as it'll be used both to indicate the last selected subreddit when the sample is loaded, and to be manipulated directly from the UI as the user changes the selection. string SelectedSubreddit, which is the currently selected subreddit.This property is never updated, so it doesn't need to be observable either. IReadOnlyList Subreddits, which is a readonly list with the names of the subreddits that we allow users to choose from.Here we're just using object as a placeholder, as we haven't created a model to represent posts yet. ObservableCollection Posts, which is the observable list of loaded posts.Properties: we need to expose a number of values to the UI, which we can do with either observable properties if they're values we intend to completely replace, or with properties that are themselves observable (eg.This will also allow us to potentially change the command type in the future without having to worry about any UI component relying on that specific type being used. Here we're exposing the command through the IAsyncRela圜ommand interface, to avoid strong references to the exact command type we're using. We can use the AsyncRela圜ommand type to wrap a private method that will fetch the posts from Reddit. Commands: we need the view to be able to request the viewmodel to reload the current list of posts from the selected subreddit.Let's start with the viewmodel that will power the subreddit widget and let's go over the tools we need: We'll just assign a sample text to all loaded posts and display that directly, to make things simpler. For the purposes of this sample, we don't need to be able to handle all the possible post types.We want the subreddit widget to also offer a refresh button to reload the current subreddit.We want users to be able to select a subreddit from a list of available options, and we want to save the selected subreddit as a setting and load it up the next time the sample is loaded.The two widget need to be self contained and without strong references to one another. A minimal Reddit browser made up of two "widgets": one showing posts from a subreddit, and the other one showing the currently selected post.Let's start by outlining exactly what we want to build: In this case, we want to build a very simple and minimalistic Reddit browser for a select number of subreddits. Now that we've outlined all the different components that are available through the package, we can look at a practical example of them all coming together to build a single, larger example.
