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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:11:31+00:00 2026-05-21T19:11:31+00:00

I have been playing around and looking around on how to Bind a modelview

  • 0

I have been playing around and looking around on how to Bind a modelview to a view, but i cant seem to work it out.
I have a view called Search and I want to bind it to SearchModelView.
View has one button and one textbox and looks:

<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >

    <ComboBox Height="23" HorizontalAlignment="Left" Margin="12,40,0,0" Name="comboBox1" VerticalAlignment="Top" Width="174" />
    <Label Content="Client:" Height="28" HorizontalAlignment="Left" Margin="0,12,0,0" Name="label1" VerticalAlignment="Top" Width="71" />
    <Label Content="Client Reference:" Height="28" HorizontalAlignment="Left" Margin="0,69,0,0" Name="label2" VerticalAlignment="Top" Width="117" />
    <TextBox  
        x:Name="clientRefTxt"
        Text="{Binding Path=ClientRef, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
        Height="23" 
        HorizontalAlignment="Left" 
        Margin="12,103,0,0" 
        VerticalAlignment="Top" 
        Width="174" />
    <Button 
        Content="Search Debtors" 
        Height="23" 
        HorizontalAlignment="Left" 
        Margin="12,140,0,0" 
        Name="button1" 
        VerticalAlignment="Top" 
        Width="89" 
        Command="{Binding Path=SearchCommand}"/>

</Grid>

And I want it to bind to SearchViewModel:

namespace Master.ViewModel
{

public class SearchViewModel:WorkspaceViewModel
{
    RelayCommand _searchCommand;
    readonly Search _search;


    #region Search Properties
    public string ClientRef
    {

        get { MessageBox.Show("GET CLIENTREF"); return _search.ClientRef; }
        set
        {
            MessageBox.Show("SET CLIENTREF");
            if (value == _search.ClientRef)
                return;
            _search.ClientRef = value;
            base.OnPropertyChanged("ClientRef");
        }
    }

    #endregion

    public ICommand SearchCommand
    {
        get
        {
            MessageBox.Show("SEARCHCOMMAND");

            if (_searchCommand == null)
            {
                _searchCommand = new RelayCommand(
                    param=> this.Search(),
                    param=> this.CanSearch
                    );
            }
            return _searchCommand;
        }
    }

    public void Search()
    {
        MessageBox.Show("SEARCHING");
    }

    bool CanSearch
    {
        get { return true; }
    }
}

}

I removed all the assemblies at the top but assume that they are all there. Also note that SearchViewModel is in a separate dll, not in the exe with the View.
Any help would be great or at least a pointer in the write direction, I have already read the msdn article on MVVM and that didnt help…I kinda need a better rundown on binding those too pieces.
Thanks in Advance.
P.S.
Some more details:
SearchViewModel belongs to Master.ViewModel
SearchView is part of GUI.View
I have and idea how the binded objects work, im not to sure on how to bind the view to the viewmodel

  • 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-21T19:11:32+00:00Added an answer on May 21, 2026 at 7:11 pm

    Is your View a Grid? I’ve only used UserControl or Window types as Views, but you may have success using a Grid.

    Regardless, this is the cleanest way to instantiate the ViewModel with a UserControl View. Just replace the UserControl tags with Grid tags if you’re using a Grid.

    <UserControl ...(blah blah)
        xmlns:viewmodel="clr-namespace:Master.ViewModel">
        <UserControl.DataContext>
            <viewmodel:SearchViewModel/>
        </UserControl.DataContext>
    

    I believe keeping out of the View’s code unless necessary is the preferred pattern for MVVM – let the XAML wire things up for you when possible.

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

Sidebar

Related Questions

I have been looking at and playing around with IVY of late for a
I have been playing around with the postgresql.conf file for a couple days now.
I have been playing around with the EF to see what it can handle.
I have been working with PostgreSQL, playing around with Wikipedia's millions of hyperlinks and
I have been playing with this for a while, but the closest I have
I have been playing around with Scala parser combinators for some time now, and
I have been playing around with the dynamic abilities of powershell and I was
I have been playing around with the merge command in R and am trying
I have been playing around JavaScript for a year or so, one thing I
I have been playing around with Apache CXF, in particular the various data bindings

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.