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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:49:46+00:00 2026-05-27T11:49:46+00:00

I have a class in WCF: [DataContract] public class Usuario { [DataMember] public int

  • 0

I have a class in WCF:

[DataContract]
public class Usuario
{
    [DataMember]
    public int ID { get; set; }

    [DataMember]
    public string Nombre { get; set; }

    [DataMember]
    public string Contraseña { get; set; }
}

In WP7 Proyect read ObservableCollection from WCF and load a ListPicker with:

lpUsuarios.ItemSource = listUsuarios;

This work ok.

Now, in WP7 use “Usuario _usuario = new Usuario()” for local variable.

The problem is, if I save the variable _usuario with IsolatedStorage and then load and apply in: lpUsuarios.SelectedItem = _usuario, causes the error: SelectedItem must always be set to a valid value.

Example:

Usuarios _usuario = new Usuario();

private void ButtonSave_Click(object sender, RoutedEventArgs e)
{
     var settings = IsolatedStorageSettings.ApplicationSettings;
     _usuario = lpUsuarios.SelectedItem as Usuario;

     settings.Add("test", _usuario);
     settings.Save();
}

Now, close the application and then open:

private void ButtonLoad_Click(object sender, RoutedEventArgs e)
{
     settings.TryGetValue<Usuario>("test", out _usuario);            
     lpUsuarios.SelectedItem = _usuario;  <--- ERROR SelectedItem must....
}

In vs2010 debug, when open the application and load the variable _usuario, value is correct, but not work.

Error in: SelectedItem must always be set to a valid value, in ListPicker.cs

Location in ListPicker.cs:

        // Synchronize SelectedIndex property
        if (!_updatingSelection)
        {
            _updatingSelection = true;
            SelectedIndex = newValueIndex;
            _updatingSelection = false;
        }

Any solution?


If I use SelectedIndex, work ok, thanks Etch.

But now, the problem is if I want use:

    public override bool Equals(object obj)
    {
        return ID == (obj as Users).ID;
    }

    public override int GetHashCode()
    {
        throw new NotImplementedException();
    }

Where implement that, ¿in WCF class, in ModelView?

In XAML use:

    SelectedItem={Binding SelectedUser, Mode=TwoWay}"

And in ModelView use:

    private Usuario selectedUser;
    public Usuario SelectedUser
    {
        get
        {
            return selectedUser;
        } //----------------if i use modelview, the error is produced here
        set
        {
            selectedUser= value;
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs("SelectedUser"));
            }
        }
    }

WCF class:

   [DataContract]
   public class Usuario
   {
       [DataMember]
       public int ID { get; set; }

       [DataMember]
       public string Nombre { get; set; }

       [DataMember]
       public string Contraseña { get; set; }
   }
  • 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-27T11:49:47+00:00Added an answer on May 27, 2026 at 11:49 am

    Your collection doesn’t have item that you want to select. Even if looks the same, smell the same, but it’s a different object. Your Users class must override Equals method for this:

        public class Users
        {
            public int ID { get; set; }
            public string Nombre { get; set; }
    
            public override bool Equals(object obj)
            {
                return ID == (obj as Users).ID;
            }
    
            public override int GetHashCode()
            {
                throw new NotImplementedException();
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following DTO definition:- [DataContract] public class AddProductDTO { [DataMember] public string
Given that I have the following WCF service: class LookUpService { public List<County> GetCounties(string
I have WCF service that return Json. Data contract defined below [DataContract] public class
I have a class [DataContract] public class Car { public bool pbIsHatchBack; string prSt
I need help with wcf service. i have a ajax-enabled wcf service: public class
How do I define DataContract for abstract classes in WCF? I have a class
I have a WCF service which all operations return type is OperationStatus: [DataContract] public
My AJAX-enabled WCF service returns JSON using this contract, [DataContract] public class JQGridContract {
When creating a wcf class I used to do [DataContract] Public class Customer {
I have a class Actions with an Enum in it [DataContract] public class Actions

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.