Code Monkey home page Code Monkey logo

Comments (1)

KarlErickson avatar KarlErickson commented on May 23, 2024

Hi skyhoshi,

Good question! The main reason to use a view model instead of binding directly to the underlying model is to extend or reshape it. In the case of ArticleViewModel, the IsStarred property is the extension.

An alternative design would be to have ArticleViewModel contain an IsStarred property and a SyndicationItem property that exposes the underlying model object directly for one-time bindings. That way you can use the existing type while adding a VM layer just to add the UI-only property. This is a reasonable design, but you lose the ability to reshape or clean up the underlying data if you need to. With ArticleViewModel, there is a bit of clean-up that takes place in the FeedDataSource.TryGetFeedAsync method, when the ArticleViewModel properties are set.

Finally, ArticleViewModel exposes only a subset of properties available on SyndicationItem. These are the only properties that FeedDataSource will try to make sure are always available to the UI designer for binding purposes. Many SyndicationItem properties are inconsistently used by different feed providers, so it was useful to us to let the UI designer know that only the VM properties should be used to create the UI.

I hope this helps!

-Karl

from windows-appsample-rssreader.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.