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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:44:49+00:00 2026-05-25T02:44:49+00:00

I have a WPF/MVVM (using MVVM-Light) app setup with a ComboBox that is inside

  • 0

I have a WPF/MVVM (using MVVM-Light) app setup with a ComboBox that is inside a DataTemplate. The XAML of the ComboBox looks like this:

<ComboBox x:Name="cbTeachers" 
          Grid.Column="1" 
          Style="{StaticResource ComboBox}" 
          ItemsSource="{Binding Teachers}" 
          Grid.Row="3" 
          DisplayMemberPath="Name" 
          SelectedValuePath="Id" 
          IsSynchronizedWithCurrentItem="False" 
          SelectedItem="{Binding Path=SelectedTeacher}">
     <i:Interaction.Triggers>
          <i:EventTrigger EventName="SelectionChanged">
               <i:InvokeCommandAction Command="{Binding TeacherSelectedCommand}"
                                      CommandParameter="{Binding SelectedItem, ElementName=cbTeachers}" />
          </i:EventTrigger>
     </i:Interaction.Triggers>
</ComboBox>

The Teachers property for the ItemsSource is a type called ObservableRangeCollection and is based on the code found here: http://geekswithblogs.net/NewThingsILearned/archive/2008/01/16/have-worker-thread-update-observablecollection-that-is-bound-to-a.aspx, but it’s very similar to a standard ObservableCollection. The SelectedTeacher property is set when another property is set and the code looks very similiar to this:

this.SelectedTeacher = (from t in this.Teachers where t.Id == this.DataItem.Teacher.Id select t).Single();

The problem I am running into, which makes zero sense to me, is SelectedTeacher is getting reset to null once I set it. I can step through the debugger and see SelectedTeacher has a value and when I put a breakpoint on the setter for the property it definitely has the value. But then that property gets hit again with a null value. I checked the call stack and it showed the only preceeding line as being External Code (which makes sense since I only set that property in one place and it only gets hit once, as expected). Expanding the External Code option in the call stack window shows the typical WPF call stack of maybe 40 methods so it’s definitely internal to WPF and not something I am doing to make it reset. In fact, when I remove the SelectedItem=”{Binding SelectedTeacher}” the setter for that property doesn’t get called a second time (thus it retains its value), but of course the ComboBox doesn’t show the selected item either. I tried implementing a SelectedIndex option in my viewmodel but that didn’t work either. The ComboBox just won’t select the item. I can change the selected item in the ComboBox just fine, but the initial setting won’t take.

Any ideas? Based on everything I’ve searched it might be related to me using a DataTemplate, but I have to because that template is part of a parent ContentTemplateSelector implementation.

As a side note, I have multiple properties that bind to controls in this DataTemplate and this is the only one that doesn’t work. The others work perfectly. I have also tried the ComboBox with and without the “IsSynchronizedWithCurrentItem” flag and it made no difference.

  • 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-25T02:44:50+00:00Added an answer on May 25, 2026 at 2:44 am

    have you tried to remove to EventTrigger stuff and just to use

    SelectedItem="{Binding Path=SelectedTeacher, Mode=TwoWay}"
    

    with Mode=TwoWay?

    its not clear to me what you want to achieve with your EventTrigger?

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

Sidebar

Related Questions

I have a WPF app that is using the MVVM pattern. Hooking up buttons
I'm developing a WPF app using MVVM. Most of my views have only xaml
Using MVVM Light, I have two WPF applications that reference a common Views library.
I'm developing WPF applications using MVVM pattern. I have ViewModel with code like this:
I have a WPF/C# application that is using the MVVM light framework. When it
So I have a check box that fires a command using WPF/MVVM this works
I am using MVVM Light toolkit in my WPF application. I would like to
I have a WPF application using MVVM. I have some user controls that show
I have a WPF application implemented using the MVVM framework that uses an ActiveX
I am building an wpf app using MVVM. I have viewModels the employ lazy

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.