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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:42:05+00:00 2026-06-17T01:42:05+00:00

I have a WPF Window, and in that window I have a grid. I

  • 0

I have a WPF Window, and in that window I have a grid.

I use M-V-VM model and I want to add a TextBox to the grid dynamically in code(in viewmodel)

How can I get access to the grid?

  • 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-06-17T01:42:06+00:00Added an answer on June 17, 2026 at 1:42 am

    Use Supervising Controller pattern.

    Reading:

    Example implementation for CaliburnMicro MVVM framework is shown here (will work same for all other frameworks – or you can do it by hand if you are doing MVVM by yourself):

    http://drc.ideablade.com/devforce-2012/bin/view/Documentation/cocktail-tutorial-talk-to-view

    Example:

    1) Define interface IView in which ViewModel (VM) will talk to View with the required method(s)

    public interface IView 
    {
        void AddTextBoxToGrid();
    }
    

    2) Inherit code behind View from your IView and implement IView.AddTextboxToGrid() method

    public partial class View: IView 
    {
        public void AddTextBoxToGrid() 
        {  
            // implement here your custom view logic using standard code behind; 
        }
    }
    

    3) Add a property of type IView to your VM

    public class ViewModel 
    {
        public IView View { get; set; }
    }
    

    4) Set View property on VM to an instance of View as IView
    e.g. in code behind:

     DataContext.View = this as IView; 
    

    or in Caliburn you can use IScreen.OnViewAttached override method)

    public partial class View: IView 
    {
        public View()
        {
            // access you VM by the strategy of your framework or choice - this example is when you store your VM in View's DataContext
            (DataContext as ViewModel).View = this as IView;
        } 
    
        public void AddTextBoxToGrid() 
        {  
            // implement here your custom view logic using standard code behind; 
        }
    }
    

    5) In your VM call IView.AddTextboxToGrid()

    public class ViewModel 
    {
        public IView View { get; set; }
    
        public void AddTextBoxToGrid() 
        {
            if (View == null) return;
            View.AddTextBoxToGrid()
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple WPF window that has 12 buttons on it. I want
I have two images on a WPF window that are on top of each
I have a RichTextBox on a WPF window that I am using kind of
At the moment I have a DocumentViewer in a WPF window that displays an
I develop on VS2010 WPF on Window 7. I have a project that does
I have 18 Buttons within a Uniform grid on my main WPF window. I
I have a winforms application that I'd like to add a WPF user control
Does anyone knows how to use WPF in Outlook Add-ins, I have read some
I want to use RadWindow as the main window of my WPF application. So
I have a WPF application that has a main window. In that I have

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.