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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:31:49+00:00 2026-06-03T11:31:49+00:00

I have a View that is linked to my ViewModel using a DataTemplate, like

  • 0

I have a View that is linked to my ViewModel using a DataTemplate, like this

<DataTemplate DataType="{x:Type ViewModels:ViewModel}">
    <Views:View />
</DataTemplate>

The ViewModel holds a property ProcessOption that is of type MyEnum?, where MyEnum is a custom enumeration that has let’s say 3 values: Single, Multiple and All. I am trying to bind a combobox to this property, so the approach I am following is:

ViewModel has a property of List<string> that is

public List<string> Options
    {
        get 
        {
            return Enum.GetNames(typeof(MyEnum)).ToList();
        }
    }

to which I bind the ItemsSource property of the Combobox. Then, in addition to the ProcessOption property, the ViewModel also has an OptionName property (of string), which is intended to hold the selected option’s name. The ViewModel implements INotifyPropertyChanged and both properties raise the PropertyChanged event in their setters. The binding I am using then is:

<ComboBox ItemsSource="{Binding Options}"
    SelectedItem="{Binding OptionName}"
    SelectedValue="{Binding ProcessOption}"/>

This works fine up to this point. Initially the combobox is empty and both properties are null, and when the user selects an option this is propagated to the ViewModel as it should.

The problem appears when I load the data from a Database, and I want to load the controls with initial values. In this case, in the ViewModel’s constructor I have this:

this.ProcessOption = objectFromDB.ProcessOption // this is the value restored from DB,        let's say it is MyEnum.Multiple
this.OptionName = Options.First(x => x.Equals(Enum.GetName(typeof(MyEnum), objectFromDB.ProcessOption)));

The problem is, although the above sets the two properties to their correct values, they are later set to null from the Combobox binding, so the initial values are not kept. I have also tried to do something like if (value == null) { return; } in the properties’ setters, in which case they have the correct values after the View loads, however the Combobox still does not display the correct option, it is empty.

I should also note that I’ve also tried setting IsSynchronisedWithCurrentItem and it doesn’t make any difference, apart from the fact that the first element is displayed instead of the combobox being empty.

Can anyone help with this binding? Any help will be very much appreciated, this is driving me crazy!

  • 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-03T11:31:53+00:00Added an answer on June 3, 2026 at 11:31 am
    <ComboBox ItemsSource="{Binding Options}"
        SelectedItem="{Binding OptionName}"
        SelectedValue="{Binding ProcessOption}"/>
    

    Your binding doesn’t look like it should work at all — you don’t have TwoWay binding set up, and I think SelectedItem and SelectedValue is an either/or proposition.

    I suggest that you get rid of OptionName and just bind SelectedItem to ProcessOption (TwoWay) with an IValueConverter that will convert to/from string.

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

Sidebar

Related Questions

I have a View that renders something like this: Item 1 and Item 2
I have a view that will be displaying downloaded images and text. I'd like
I have a view that I would like to populate data when the next
I have a section of a view that I would like to submit to
I have a view that joins SQL Server tables on linked servers. There are
I have a set of drop down controls on a view that are linked
I have a UserMailer View that has several link_to's like so: <%= link_to('XXXXXXXX Link
I have different view controllers and i linked them using insertsubview There are atleast
I understand that ViewModel shouldn't have any knowledge of View, but how can I
I have encapsulated all my table view logic on a UITableViewController that is linked

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.