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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:55:04+00:00 2026-06-11T14:55:04+00:00

In Short I want to be able to call a method, the method takes

  • 0

In Short

I want to be able to call a method, the method takes a parameter of type ObservableCollection<Base> but I want to call it with ObservableCollection<Derived>. It says it cannot convert between the two.

Longer

I want to call a WPF Window, in it is a ListBox that will bind to an ObservableCollection. I want the window to display some basic information that are common to two different classes. The classes are Derived1 and Derived2, and are based an BaseClass. I am able to call the method had the type just been BaseClass, but I want to pass a list through.

So I have two collections :

ObservableCollection<Derived1> A;
ObservableCollection<Derived2> B;

And want to be able to call a method like the one below, with the above two collections so I don’t need to duplicate code.

public void InitialiseWindow(ref ObservableCollection<BaseClass> List)
{
    this.List=List;
}

But it throws an error:

cannot convert from 'ref System.Collections.ObjectModel.ObservableCollection<Derived1>' to 'ref System.Collections.ObjectModel.ObservableCollection<Base>'

Whilst I’m here

Would there be a better way of binding the Collection so changed made in the Window will reflect on the source, instead of using ref?

Solution

I modified the constructor for the Window so that it casts the IEnumerable to a public member of type ObservableCollection. Since the window would only be shown modally, this the member could be accessed after the window closes.

public ObservableCollection<BaseClass> List;

public InitialiseWindow(IEnumerable<BaseClass> List)
{
    InitializeComponent();
    this.List=new ObservableCollection<BaseClass>(List);
}
  • 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-11T14:55:05+00:00Added an answer on June 11, 2026 at 2:55 pm

    If you’re exposing it purely for binding purposes, it’s sufficient to pass an IEnumerable<BaseClass> reference. The data binding system will automatically inspect the actual instance to see if it implements INotifyCollectionChanged, so it does not need the bound property to be typed explicitly as an ObservableCollection.

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

Sidebar

Related Questions

I want to be able to call a method that creates an object and
Long story short, I want users to be able to call the value of
I've got about 2500 short phrases in a file. I want to be able
I have this restfull service that I want to be able to call for
Ok. Long story short. My camera has a method which takes a photo and
In short I want a call a function jAlert() from jquery.alert.js file in a
I want to be able to sort files based on what day they were
I want to be able to achieve the following using guice/gin: Get all sort
I have main categories and sub categories. I want to be able to sort
In short: I want to have two fullscreen views, where I can switch between

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.