2010-10-22 10 views
5

En el código fuente de AutoCompleteBox (descargable desde Microsoft) me encontré con lo siguiente:Silverlight 4 AutoCompleteBox, el establecimiento de SelectedItem en null

/// <summary> 
/// Called when the selected item is changed, updates the text value 
/// that is displayed in the text box part. 
/// </summary> 
/// <param name="newItem">The new item.</param> 
private void OnSelectedItemChanged(object newItem) 
{ 
    string text; 

    if (newItem == null) 
    { 
    text = SearchText; 
    } 
    else 
    { 
    text = FormatValue(newItem, true); 
    } 

    // Update the Text property and the TextBox values 
    UpdateTextValue(text); 

    // Move the caret to the end of the text box 
    if (TextBox != null && Text != null) 
    { 
    TextBox.SelectionStart = Text.Length; 
    } 
} 

Lo que me preocupa es {text = SearchText;} línea. Si enlace SelectedItem a mi ViewModel y después de una entrada de búsqueda en AutoCompleteBox, SearchText no está vacío, cuando los datos subyacentes se restablecen a null, AutoCompleteBox puede mostrar SearchText en lugar de cadena vacía. ¿Alguien puede explicar por qué está escrito de esta manera y sugerir una solución alternativa?

+0

Gracias por apuntarme en la dirección correcta. –

Respuesta

1

Creo que es así que cuando no hay un elemento de búsqueda real, la caja muestra algo así como "Buscar aquí". Por ejemplo, vea el cuadro de búsqueda de StackOverflow, que dice "buscar" cuando está vacío.

+0

Sonidos y apariencia desde el código limitado disponible. – cofiem

1

Esto es realmente molesto y todavía tengo que encontrar una solución. Está en el rastreador de problemas de Silverlight Toolkit here. También he leído algo here sobre la configuración de ItemsSource para anular con la que voy a jugar.

Lo actualizaré si encuentro una solución.

Cuestiones relacionadas