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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:59:06+00:00 2026-05-16T23:59:06+00:00

Okay here’s the situation. Net 4 WPF NO Silverlight. I have several Views that

  • 0

Okay here’s the situation. Net 4 WPF NO Silverlight.

I have several Views that present a datagrid showing the contents of some observable collections e.g.

ObservableCollection<ClassAViewModel> sourceA;
ObservableCollection<ClassBViewModel> sourceB;
ObservableCollection<ClassCViewModel> sourceC;

The collections are populated by a call to the data access layer. I can display this data easily enough with a Usercontrol that contains a datagrid bound to the appropriate collection.
I have

  • ClassAView and ClassAViewModel to
    control display of single ClassA
    data,
  • ClassBView and ClassBViewModel to
    control display of single ClassB data
  • ClassCView and ClassCViewModel to
    control display of single ClassC data

I also have:

  • AllClassAView and AllClassAViewModel
    to display a DataGrid with data
    relating to all ClassA instances.
  • AllClassBView and AllClassBViewModel
    to display a DataGrid with data
    relating to all ClassB instances.

    etc.

Now say that ClassA contains a subset of the ClassB collection and a subset of the ClassC collection etc.

In my resource file I have bound the ViewModels and their Views together in the following manner (vm and vw are the namespaces of where they are) :

<DataTemplate DataType="x:Type vm:ClassAViewModel}">
  <vw:ClassAView/>
</DataTemplate>

Now what I was hoping to do was use an AllClassBView or AllClassBViewModel within the ClassAView to display the subset of ClassB instances that relate to it.

What is the best way to call up this data?

Can I re-use the AllClassBView UserControl to display a subset of the ClassB ObservableCollection and what is the best way of doing this?

I don’t want to place any code within the ClassAView.cs file only within the ClassAView.xaml or ClassAViewModel.

Should I just add a new property to the AllClassBView and use that to filter the list? For example within ClassBViewModel where I generate the list of ClassBViewModels (for use in the DataGrid) I can use:

if(this.ClassA_Id!=0)
{
  List<ClassBViewModel> all = (from ClassB in this.DataRepository.GetClassBs().Where(x=>x.ClassA_Id == this.ClassA_Id) select new ClassBViewModel()).ToList();
}
else
{
  List<ClassBViewModel> all = (from ClassB in this.DataRepository.GetClassBs() select new ClassBViewModel()).ToList();
}

this.sourceB= new ObservableCollection<ClassBViewModel>(all);
  • 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-16T23:59:07+00:00Added an answer on May 16, 2026 at 11:59 pm

    Well I’ve cracked it.

    My problem may not have come across as very clear.

    Whether my solution is good practice or not I don’t know.

    What I have done is as follows:

    I placed an extra property into the AllClassBViewModel that allows me to filter its list of ClassBViewModels to those that relate to ClassA.

    public ulong ClassA_Id{get;set;}
    

    So now when the AllClassBViewModel builds its list of ClassBViewModels it can now filter them by:

    if(this.ClassA_Id!=0)
    {
      List<ClassBViewModel> all = (from ClassB in this.DataRepository.GetClassBs().Where(x=>x.ClassA_Id == this.ClassA_Id) select new ClassBViewModel()).ToList();
    }
    else
    {
      List<ClassBViewModel> all = (from ClassB in this.DataRepository.GetClassBs() select new ClassBViewModel()).ToList();
    }
    
    this.sourceB= new ObservableCollection<ClassBViewModel>(all);
    

    I added a property and field to my ClassAViewModel that were of the AllClassBViewModel type.

    private AllClassBViewModel fieldAllClassBViewModel;
    public AllClassBViewModel AllClassBVM{get{return this.fieldAllClassBViewModel;}}
    

    I then added an entry to an AllClassBView into the ClassAView that had a data context bound to the AllClassBVM property within ClassAViewModel.

    <vw:AllClassBView DataContext="{Binding AllClassBVM}"/>
    

    No all I have to do is check through the command binding.

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

Sidebar

Related Questions

Okay, here's my situation. I have a WPF app that I have created that
Okay here's my situation. I have the following branches development development-kirby (270 commits ahead
Okay here is what I'm trying to do: I have a model object that
Okay, here's the scenario. I have a utility that processes tons of records, and
Okay so here is the problem I am having. I have several unit tests
Okay so here is my database: I have a page on my .net form
Okay so here's the situation. I have this page of data. After the data
Okay so here my issue, I have a list of items that when a
Okay, I'm confused here. I have a properties file with some SQL scripts that
Okay, here we go... I have a page XYZ with a button that's supposed

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.