Quantcast
Channel: Silverlight Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 801

Created Issue: WP7 SelectedItem error "SelectedItem must always be set to a valid value" [9990]

$
0
0
Hello, 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<Usuario> from WCF and load in 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 Button_Click(object sender, RoutedEventArgs e)
{
_usuario = lpUsuarios.SelectedItem as Usuario;
guardarDatos(x);

_usuario = leerDatosGenericos();
lpUsuarios.SelectedItem = x;
}

For save and load in IsolatedStorage use:

public static Usuario leerDatosGenericos()
{
using (var contenedorDatosUsuario = IsolatedStorageFile.GetUserStoreForApplication())
{
if (contenedorDatosUsuario.FileExists("a.xml"))
{
using (var iss = contenedorDatosUsuario.OpenFile("a.xml", System.IO.FileMode.Open))
{
return SilverlightSerializer.Deserialize(iss) as Usuario;
}
}

return null;
}
}

public static void guardarDatos(object datos)
{
using (var contenedorDatosUsuario = IsolatedStorageFile.GetUserStoreForApplication())
{
if (contenedorDatosUsuario.FileExists("a.xml"))
{
contenedorDatosUsuario.DeleteFile("a.xml");
}
using (var iss = contenedorDatosUsuario.CreateFile("a.xml"))
{
SilverlightSerializer.Serialize(datos, iss);
}
}
}



Thanks and sorry for my English, :)

Viewing all articles
Browse latest Browse all 801

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>