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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:36:54+00:00 2026-05-23T11:36:54+00:00

I have about a dozen different views, which are pretty much identical except for

  • 0

I have about a dozen different views, which are pretty much identical except for the names of the properties they bind to. For example, the below sections are form two different views:

<TextBlock Text="{Binding PersonName}">       
<GroupBox Header="{Binding PersonName}">
  <ComboBox Text="{Binding SelectedPersonName}" SelectedItem="{Binding SelectedPerson}" ItemsSource="{Binding People}" DisplayMemberPath="PersonName"/>
</GroupBox>
<igDP:XamDataGrid DataSource="{Binding PersonEntries}"


<TextBlock Text="{Binding CarName}">       
<GroupBox Header="{Binding CarName}">
  <ComboBox Text="{Binding SelectedCarName}" SelectedItem="{Binding SelectedCar}" ItemsSource="{Binding Cars}" DisplayMemberPath="CarName"/>
</GroupBox>
<igDP:XamDataGrid DataSource="{Binding CarEntries}"

Note that the only real differences between these to blocks are the names of the bindings used (Person vs Car).

I was thinking of maybe creating one BaseView class that the other views inherit from. This base class would use generic enough binding names so that it can be reused, such as:

<TextBlock Text="{Binding DataItemName}">       
<GroupBox Header="{Binding DataItemName}">
  <ComboBox Text="{Binding SelectedDataItemName}" SelectedItem="{Binding SelectedDataItem}" ItemsSource="{Binding DataItems}" DisplayMemberPath="DataItemName"/>
</GroupBox>
<igDP:XamDataGrid DataSource="{Binding DataItemEntries}"

This way, my PersonsView and CarsView can inherit from BaseView and that’s it. I would also have to make changes to the ViewModels though, so that they expose the correctly named properties, such as DataItem. I guess I could create a base ViewModel interface that exposes the desired properties and have the other ViewModels implement that.

Any thoughts on the above? Would it be a bad idea to try to create a base view or base view model as I described?

Thanks.

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

    You’re really going to create the inheritance in your view models, not your views. I’d define an ItemViewModelBase class that exposes ItemName, Items, and SelectedItemName properties and derive my view models from it.

    The views themselves don’t really “inherit” per se. In fact, unless you need customization in the view, you don’t need multiple views: you only need one view that presents ItemViewModelBase objects.

    Of course, if you do need the views to be different, you can do a certain amount of customization, e.g.:

    <DataTemplate DataType="{x:Type CarsViewModel}">
       <DockPanel>
          <Label DockPanel.Dock="Top">Cars</Label>
          <local:ItemView/>
       </DockPanel>
    </DataTemplate>
    

    This is a cool idea for another reason. Right now, if you don’t provide a data template, whenever WPF presents an object it creates a TextBlock containing object.ToString(). Implementing a generic base class gives you a way to globally override this behavior just by creating one data template, e.g.:

    <DataTemplate DataType="{x:Type ItemViewModelBase}">
       <TextBlock Text="{Binding ItemName}"/>
    </DataTemplate>
    

    That’s not easier than just overriding ToString() to return ItemName (which is where I’d start), but if (for instance) you want a ToolTip that displays detailed information when the user mouses over it, you just add it to this one template and it works everywhere in your UI.

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

Sidebar

Related Questions

I have an object that contains about half a dozen properties. I expect to
In my app, I have about a dozen different view controllers, pushed onto or
I need a status column that will have about a dozen possible values. Is
We have a set of about two dozen classes that inherit from a base
I've been working with about a dozen WCF Services that have been deployed to
In my application I have about a dozen of Activities. However, most of these
I've never programmed a game, but have about a dozen years programming interfaces. After
I've never programmed a game, but have about a dozen years programming interfaces. After
I have spent hours reading a couple dozen different blogs and others q's here
I have about 100 databases (all the same structure, just on different servers) with

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.