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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:21:58+00:00 2026-05-30T11:21:58+00:00

I have a grid which I call let’s say FooHistory . Now I need

  • 0

I have a grid which I call let’s say FooHistory. Now I need plenty of functionality related to that so I go ahead and I create a FooHistory class. Now I have a FooHistory class and a control.

In my MainWindow constructor I create a new instance of this class and pass the instance of this (i.e. the MainWindow) to the FooHistory class sort of like dependency injection. Then later when the FooHistory class wants to interact with the FooHistory control, I do things like this.mainWindow.FooHistory.Items.Add(...).

My question is that is this the recommended way to write WPF applications or am I missing some fundamental approaches?

  • 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-30T11:22:00+00:00Added an answer on May 30, 2026 at 11:22 am

    We use for our programs the MVVM approach. While the details may differ from program to program MVVM is usually build with 3 main parts.

    Model:
    This is you data object. This may be business data like

    class Account
    {
        string Name {get;set;}
        string Address {get;set;
    }
    

    but can also be UI data like:

    class Window
    {
        Point Position {get;set;}
        Size Size {get;set;}
    }
    

    These objects are for holding data, nothing more. No events, no commands no methods (Thats one point where different interpretation of MVVM differ).

    ViewModel:
    This is to wrap the model and provide logic around the underlying model. This class is also used to convert a business model property into a view understandable property.

    class AccountViewModel
    {
        public AccountViewModel(Account aWrappedModel)
        {
        }
    
        string Name {get {return Model.Name;} }
    
        AddressObject Address { get{ return new AddressObject( Model.Address ); }
    }
    

    View:

    Is the wpf part this can be user controls, custom controls, windows, datatemplates etc.
    Despite a common believe, its fine to have code behind for view otherwise you have to bend over backwords just because you heard that the view isn’t allowed to have code.

    The usual approach now is to create a model, one or more viewmodels and set these viewmodels as DataContext in your view. Sometimes you need a DataTemplate to display the given data, like a DataTemplate for our AccountViewModel.

    <DataTemplate DataType="{x:Type AccountViewModel}">
        <StackPanel>
            <TextBox Text="{Binding Name}/>
            <Button Content="Save" Command="{Binding SaveAccount}"/>
        </StackPanel>
    </DataTemplate>
    

    This design makes heavy use of Databinding which is fundamental for MVVM and works quite nicely. Of course a couple of problems can arise like: How to handle Collection with models? How to handle events in the viewmodels coming from the ui? How to store my data?

    But for these you find many resources here and in the web. But this answer should give you a rough overview of how i and alot other people work with WPF.

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

Sidebar

Related Questions

I have a grid with one TemplateField which is a checkbox and say 2
I have a grid (DevExpress XtraGrid, if that matters) which is bound to a
I have a parent grid that contains multiple row definitions, all of which have
I have an MVC grid which is rendered in by a json call on
I am using extjs grid, and I have a jQuery timer, which will call
I have 2 comboboxes which we will call cbo1 and cbo2. Now, there is
I need to have some sort of scrollview which is a grid 3 x
I have a user control, call it UserControl , that has a grid with
I have a normal WPF window, let's call it TopLevel which has a bunch
Hi I have a grid which used to display call details. It is displaying

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.