Tengo un problema al utilizar el enlace bidireccional con un listpicker. Puedo establecer el valor usando C# pero no en el SelectedItem=".."
en xaml. El enlace está devolviendo el valor correcto (y es un valor en el listpicker) ya que lo he enviado un mensaje de texto asignando el texto a un bloque de texto.Problema de configuración de enlace bidireccional
Cuando se carga la página, la unión utilizados en la ListPicker provoca una System.ArgumentOutOfRangeException
El código que estoy utilizando para configurarlo es:
// Update a setting value. If the setting does not exist, add the setting.
public bool AddOrUpdateValue(string key, Object value)
{
bool valueChanged = false;
try
{
// If new value is different, set the new value
if (settingsStorage[key] != value)
{
settingsStorage[key] = value;
valueChanged = true;
}
}
catch (KeyNotFoundException)
{
settingsStorage.Add(key, value);
valueChanged = true;
}
catch (ArgumentException)
{
settingsStorage.Add(key, value);
valueChanged = true;
}
catch (Exception e)
{
Console.WriteLine("Exception occured whilst using IsolatedStorageSettings: " + e.ToString());
}
return valueChanged;
}
// Get the current value of the setting, if not found, set the setting to default value.
public valueType GetValueOrDefault<valueType>(string key, valueType defaultValue)
{
valueType value;
try
{
value = (valueType)settingsStorage[key];
}
catch (KeyNotFoundException)
{
value = defaultValue;
}
catch (ArgumentException)
{
value = defaultValue;
}
return value;
}
public string WeekBeginsSetting
{
get
{
return GetValueOrDefault<string>(WeekBeginsSettingKeyName, WeekBeginsSettingDefault);
}
set
{
AddOrUpdateValue(WeekBeginsSettingKeyName, value);
Save();
}
}
Y en el XAML:
<toolkit:ListPicker x:Name="WeekStartDay"
Header="Week begins on"
SelectedItem="{Binding Source={StaticResource AppSettings},
Path=WeekBeginsSetting,
Mode=TwoWay}">
<sys:String>monday</sys:String>
<sys:String>sunday</sys:String>
</toolkit:ListPicker>
El StaticResource AppSettings
es un recurso de un archivo .cs separado.
<phone:PhoneApplicationPage.Resources>
<local:ApplicationSettings x:Key="AppSettings"></local:ApplicationSettings>
</phone:PhoneApplicationPage.Resources>
Gracias de antemano
¿Qué quiere decir cuando escribe '{StaticResource AppSettings}'? ¿Es un nombre de 'recurso' definido en algún lugar en' XAML' o 'clase estática'? – decyclone
Sí, lo siento, olvidé mencionar que AppSettings es un archivo de clase separado – Jamie
¿Es una clase estática? ¿Está confundiendo '{x: Static AppSettings.WeekBeginsSetting}' con su enlace actual? Porque Silverlight no admite '{x: Static}'. – decyclone