Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 982101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:38:39+00:00 2026-05-16T04:38:39+00:00

I am a big proponent of the MVVM pattern with Silverlight. Currently I wire

  • 0

I am a big proponent of the MVVM pattern with Silverlight. Currently I wire the ViewModel up to the View by newwing up the ViewModel in the code behind of the view, thusly:

public partial class SomePage : UserControl
{
    public SomePage()
    {
        InitializeComponent();

        // New up a ViewModel and bind to layout root
        var vm = new SomeViewModel();
        LayoutRoot.DataContext = vm;
    }
}

And then all the binding is handled in the View and all the logic is handled in the ViewModel, as the pattern intends.

However, wiring them up this way means that the designer doesn’t work well, and I can’t use Expression Blend design time data. I know that there are libraries such as MVVM Light that will help to get all this working, but I prefer not to bring in a library, as it is “one more thing” to have to deal with.

Is there a simple pattern for getting MVVM wired up in Silverlight while maintaining designer functionality, especially in Blend? I’ve done some Googling but there are so many outdated articles out there and so much confusion between WPF and Silverlight and older versions that I have a hard time figuring out which to use.

BTW I’m focused on SL4 with VS2010 if it matters.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:38:39+00:00Added an answer on May 16, 2026 at 4:38 am

    There are a few methods you can use.

    First, let Expression’s Sample Data and design-time attributes (i.e. d:DataContext) take over in the designer. In your code, you would simply condition the view model binding:

    if (!DesignerProperties.IsInDesignTool)
    {
       var vm = new SomeViewModel();
       LayoutRoot.DataContext = vm; 
    }
    

    Second, you can have a special design-time view model that you bind instead:

    LayoutRoot.DataContext = DesignerProperties.IsInDesignTool ?
        new DesignViewModel() : new MyViewModel(); 
    

    Finally, another way is to manage the data within the view model. I don’t like this because it spreads the responsibility across all view models, but you have more precision:

    // constructor
    private Widget[] _designData = new[] { new Widget("Test One"), new Widget("Test Two") };
    
    public MyViewModel()
    {
       if (DesignerProperties.IsInDesignTool)
       {
           MyCollection = new ObservableCollection<Widget>(_designData);       
       }
       else 
       {
           MyService.Completed += MyServiceCompleted;
           MyService.RequestWidgets();
       }
    }
    
    private void MyServiceCompleted(object sender, AsynchronousEventArgs ae)
    {
       // load up the collection here
    }
    

    Hope that helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Whilst trying to get our app working in Firefox (I'm a big proponent of
I am a big proponent of using super clean urls for all pages and
A big reason why I use OOP is to create code that is easily
The big problem lies in the fact that the code, no matter which number
I implement very big script logic using jquery plugin at caret(http://code.google.com/p/jquery-at-caret/), but now when
Big question update before continue: Is Items.SortDescription getting fired INotifyPropertyChanged events? From the code
I have a big problem that I am capturing a view into a Bitmap
Big problem. I'm not sure what it was that I did, but it seems
(big) (big) Somewhere along the way into the function animationWithFrames , my vector loses
how big (binary(xy)) should I make my table column in SQL database if I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.