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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:35:55+00:00 2026-06-06T23:35:55+00:00

I am trying to learn the MVVM pattern in WPF and I am running

  • 0

I am trying to learn the MVVM pattern in WPF and I am running into some issues with bindings and collections. I don’t like binding to the index of the collection because the collection changes.

I have MyModelClass : ObservableCollection<MyData>

The MyData class has a property called DataValue in it to hold my custom information. I fill the MyModelClass with MyData objects. In the view model class (MyViewModel) I have a property CurrentData of type MyModelClass.

Now in this case, my binding is to a combo box.
Here is what the binding looks like:

<ComboBox Name="cmbxData" 
  ItemsSource="{Binding Path=CurrentData}"
  DisplayMemberPath="DataValue"
  SelectedValuePath="DataValue"
  SelectedValue="{Binding Path=CurrentData[0].DataValue}"/>

This all works fine and the MyViewModel class has the interface setup for PropertyChanged notifications.
I need to refresh the information this holds every few seconds.

I am refreshing the collection by doing something like this inside the MyModelClass:

public Class MyModelClass : ObservableCollection<MyData>
{
    private static MyModelClass current = null;
    public static MyModelClass Current
    {
        get
        {
             if(current == null)
                 current = new MyModelClass();

             return current;
        }
    }

    private void UpdateModel(MyData newData)
    {
         MyModelClass newModel = new MyModelClass();
         newModel.Add(newData);
         current = newModel;

    }
}

Inside MyViewModel there is this:

MyModelClass CurrentData = MyModelClass.Current;

I tried my best to give as much code as I could and keep it simple. Please let me know if there is more needed to clarify. Thank you for any suggestions on how to fix my issue.

In case you missed it:
Problem: How can I bind to the collection, or the value I want to display in the collection, without using the index like I have shown above (SelectedValue="{Binding Path=CurrentData[0].DataValue}")? How can I fix this or change my implementation to be correct?

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-06-06T23:35:57+00:00Added an answer on June 6, 2026 at 11:35 pm

    Add a property on MyModelClass called “SelectedData” or something similiar.
    Then bind that property to the SelectedItem property of ComboBox

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

Sidebar

Related Questions

I'm trying to learn how to use WPF binding and the MVVM architecture. I'm
I'm trying to learn MVVM, but there is something I don't understand yet. Currently,
I'm trying to learn the MVVM pattern. The main problem I'm having is learning
Trying to learn some F# and I've run into a couple of hangups. Here's
I'm trying to learn the MVVM software design pattern. I've got Matthew MacDonald's book,
Trying to learn about php's arrays today. I have a set of arrays like
Trying to learn MVP pattern with C#... Does anyone know of any particularly good
Im trying to learn a bit about c++ and have run in to some
Trying to learn some R after doing mostly Haskell for rather a long time
trying to learn some html/css and I'm having a problem with fixed position divs.

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.