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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:25:16+00:00 2026-05-31T21:25:16+00:00

I have a TreeView that permits the user to select different items. The display

  • 0

I have a TreeView that permits the user to select different items. The display for each item is determined using Data Templates with the DataType set to the appropriate ViewModel type. The DataContext is automatically set based on the selected item in the tree view to the appropriate ViewModel.

Here’s the problem:

One of the DataTemplates has a ComboBox bound to an ObservableCollection to get the list of items and a property to get/set the SelectedValue in the ViewModel.

When I select one item of this type, and then select another item of the same type, the ComboBox displays blank instead of the correct selected item. It appears that the Combo Box is setting the SelectedValue property to NULL immediately after the transition to the new item, and then never updating.

<ComboBox Margin="1,0" 
    ItemsSource="{Binding ItemsToSelect}" 
    SelectedValue="{Binding SelectedValue}" 
    SelectedValuePath="ValuePath" DisplayMemberPath="DisplayPath"
    IsEnabled="{Binding CanSelectItem}">
</ComboBox>

The really strange part is if I select an item of a different type between selecting items of the same type, it always displays correctly.

I’ve tried ignoring the NULL value in the SelectedValue setter, and that didn’t work regardless of whether I also raised the PropertyChanged event or not.

private MyObject selectedValue;
public MyObject SelectedValue
{
    get
    {
        return selectedValue;
    }
    set
    {
        if (value != null)
        {
            this.selectedValue = value;
        }
        this.OnPropertyChanged("SelectedValue");
    }
}

Looking at the similar questions while writing this lead me to an interesting attribute that I hadn’t found yet – IsSynchronizedWithCurrentItem from this question. At first, I thought this solved the problem, but alas it just changes the behavior somewhat.

With this attribute set to True, the combo doesn’t entirely clear its selection, but instead just marks the first item as selected. So, instead of being set to NULL, now the SelectedValue property is being set to the first item in the list.

Anyone have any ideas for a solution?

  • 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-31T21:25:17+00:00Added an answer on May 31, 2026 at 9:25 pm

    I figured out a work around, but it isn’t quite what I wanted.

    I changed the binding to use SelectedItem instead of SelectedValue, and the issue doesn’t occur.

    I got the idea from this question.

    So I changed

    SelectedValue="{Binding SelectedValue}" 
    

    To (and renamed my ViewModel Property):

    SelectedItem="{Binding SelectedItem}"
    

    After updating the uses of this property in the ViewModel, everything worked.

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

Sidebar

Related Questions

I have a TreeView that the user navigates to select an item for display
I have a treeview that is bound to a collection and each item in
I have a treeview that is bound to a database table. Each treeview item
I have a TreeView that allows users to select certain elements of hierarchical data
I currently have a treeview that displays data using a hierarchicaldatatemplate and when the
I have a treeview that represents different filter items to a set of records.
I have a TreeView that launches a new window when each of its TreeViewItems
Using WPF, I have a TreeView control that I want to set its ItemTemplate
I have a ASP.Net TreeView control that I am binding to an XML data
I have a treeview in wpf that is built using the xaml below. It

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.