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 7041297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:01:29+00:00 2026-05-28T02:01:29+00:00

I wanna implement an interface(Add behavior) for set of WPF usercontrols. I’m using MVVM

  • 0

I wanna implement an interface(Add behavior) for set of WPF usercontrols.
I’m using MVVM design pattern.
Where I should implement the interface? in usercontrol code behind or in View model class?

Ex:

My Interface is

interface IWizard
{
    event RoutedEventHandler MoveNext;
    event RoutedEventHandler MoveBack;
    event RoutedEventHandler Cancelled;   

    bool IsLast;
    bool IsFirst;
}

Now in other place I wanna access user controls which are implemented this interface as this.

 ((IWizard)userControl).MoveNext += ...
 ((IWizard)userControl).MoveBack += ...
 ((IWizard)userControl).IsLast = true; 

etc..

Implement in UserControl Code behind

I can’t acess the interface’s properties/methods directly in view model. I have to link them manually. right ?


PS: In this example I wanna Bind(TwoWay Bind) IsLast Property with a visibility of a button.

Implement in View model class

I can’t access the usercontrol as a Interface object.
ex: ((IWizard)userControl).MoveNext += ...

What is the best practice on Implementing an Interface on Usercontrol with MVVM design Pattern?

  • 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-28T02:01:30+00:00Added an answer on May 28, 2026 at 2:01 am

    In perfect-world MVVM, ViewModel has no knowledge whatsoever about View. Whether View implements any interface at all is irrelevant from ViewModel’s point of view.

    In your scenario, what I think is more important is who will respond to MoveNext, MoveBack and Canceled events. Most likely, that would be ViewModel. What that means you probably could use methods such as WizardMoved(object sender, EventArgs e) in those ViewModels. Look what we’ve done here – ViewModel needs to have kind of indirect knowledge about View. That is not a good sign.

    Perhaps instead, you could approach problem differently. Maybe what you need is IWizardMovement interface that will define methods to handle wizard moving events – and this interface will be implemented by ViewModels. So that when you pass ViewModel to View, it can easily subscribe ViewModel’s handlers to its own events (note that not it doesn’t really matter what interface View implements).

    public interface IWizardMovementViewModel
    {
        void WizardMovedNext(object sender, EventArgs e);
        void WizardMovedBack(object sender, EventArgs e);
        void WizardMoveCanceled(object sender, EventArgs e);
    }
    

    Now, since in MVVM View knows about ViewModel (and never the other way around), you can easily utilize this knowledge:

    // Wizard user control constructor
    public Wizard(IWizardMovementViewModel viewModel)
    {
        MoveNext += viewModel.WizardMovedNext;
        MoveBack += viewModel.WizardMovedBack;
        Canceled += viewModel.WizardMoveCanceled;
    }
    

    ViewModel is separated from View for good now, and how your View looks like is not important anymore (as it should never been in first place).

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

Sidebar

Related Questions

I wanna add server controls by using javascript. The main purpose of why I
i wanna add a service behavior(or anything u'll suggest) that will automatically insert the
I wanna implement a fast algorithm for a homework, but using parallel processing for
I wanna implement a javascript like method in java , is this possible ?
I wanna get the Timedate value from another page using request.querystring and then use
I wanna implement a download-and-install mechanism. I have a source link where my app
I want to implement event management in my application and i wanna know what
Wanna to split a screen for my app with two LinearLayouts. What parameters should
I have readed something about it i wanna to do some implementation using this.
I wanna implement something like in facebook: after left click on photo, it is

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.