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

  • Home
  • SEARCH
  • 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 6240821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:38:29+00:00 2026-05-24T11:38:29+00:00

I have an application I am creating in WPF, using MVVM pattern. In this

  • 0

I have an application I am creating in WPF, using MVVM pattern. In this app, I have an ObservableCollection<> of Email objects. I have a Master-details form which displays the collection in a listbox, and the class properties ‘Address’, ‘EType’ and ‘isPrimary’ are displayed in a Textbox, combobox and checkbox, respectively.

The combobox has a List<> of EmailTypes as an ItemsSource, and the selected item is bound to the Type property of the SelectedItem in the ViewModel.

Everything works great, pretty easy. However, I want to serialize the ObservableCollection for undo purposes. This works OK too, using ISerializableSurrogate (method here). With one exception:

The combobox will not bind to to the SelectedItem.EType property, at least not initially. Instead of the combobox showing the type when an email object is selected, as is the case with the pre-serialized version, the combobox is empty (unselected). If I manually select the type in the combobox, it will work, and update the Selected Emails type property. i Have to manually ‘reset’ the binding(?) between the two objects.

The Address ( a string) and CheckBox (a boolean) work fine. And the deserialized Email object DOES have the expected EType nested object coming out of the deserialize call; I can see it in the debugger while inspecting the locals.It’s as if the binding doesnt recognize the deserialized version of an EType object as a valid Etype object…

Any ideas where exactly this is falling apart? I know there are some other ways of taking care of my undo requirement, but I really want to learn why this is not working…

FYI, I know that this is not a problem with the ObservableCollection, because I can create a new ObservableCollection, manually add an original Email object and a deserialized email object, and I have the same issue.

Here are my classes, grossly simplified:

A business object here:

[Serializable]
public class Email : INotifyPropertyChanged
{
    private int _id;
    private string _address;
    private emailType _eType;
    private bool isPrimary;

    public string Address 
    {
        get { return _address; }
        set 
        { 
            _address = value;
            onPropertyChanged(new PropertyChangedEventArgs("Address"));
        }
    }
    public EmailType EType 
    {
        get { return _eType; }
        set 
        { 
            _type = value;
            onPropertyChanged(new PropertyChangedEventArgs("EType"));
        }
    }
    public bool IsPrimary 
    {
        get { return _isPrimary; }
        set 
        { 
            _isPrimary = value;
            onPropertyChanged(new PropertyChangedEventArgs("IsPrimary"));
        }
    }

A lookup class here:

[Serializable]
public class emailType
{
    protected readonly int _id;
    protected String _name;

    public int Id
    {
        get { return _id; }
    }
    public String Name
    {
        get { return _name; }
    }
}

And the combobox in XAML:

<ComboBox Grid.Column="1" Grid.Row="3" Height="23" HorizontalAlignment="Left" Margin="3" Name="typeComboBox" VerticalAlignment="Top" Width="190" 
              ItemsSource="{Binding EmailTypes}" IsSynchronizedWithCurrentItem="False"   >
        <ComboBox.SelectedItem>
            <Binding Path="SelectedEmail.EType"  NotifyOnValidationError="True" UpdateSourceTrigger="PropertyChanged">
                <Binding.ValidationRules>
                    <local:NullValueRule></local:NullValueRule>
                </Binding.ValidationRules>
            </Binding>
        </ComboBox.SelectedItem>

    </ComboBox>
  • 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-24T11:38:31+00:00Added an answer on May 24, 2026 at 11:38 am

    You will need to override the Equals method in the emailType class. Without doing so, the implementation that is inherited from object is used.

    This implementation compares the object references. The deserialized object might have all the same properties however it os a different object and will not be ‘equal’.

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

Sidebar

Related Questions

I am creating an touch screen application using Swing and have a request to
I am creating paint like application using WPF. Now i need to create control
In my WPF application, I host Win32 content using HwndHost. However, creating a HwndHost
I am creating a wpf application and in which i have to create a
I have a C# Application I am creating that stores all data in SQL
I am creating an application in which I have two mxml components, MainPanel.mxml and
I have a C application that I've created in VS2008. I am creating a
We are creating an XBAP application that we need to have rounded corners in
When creating a web application, and lets say you have a User object denoting
I'm using AvalonDock in a WPF application, and need to persist the layout of

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.