Aquí es una respuesta acceso rápido a la solución de Microsoft sugerido por Derek. En lugar de la descarga y tamizado a través de todas las cosas Prisma, simplemente copiar esta clase en su proyecto a continuación, siga los pasos después de activarlo:
UpdateBindingOnPropertyChangedBehviour.cs
using System;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Interactivity;
namespace MyCompany.MyProduct
{
/// <summary>
/// Custom behavior that updates the source of a binding on a text box as the text changes.
/// </summary>
public class UpdateTextBindingOnPropertyChanged : Behavior<TextBox>
{
/// <summary>
/// Binding expression this behavior is attached to.
/// </summary>
private BindingExpression _expression;
/// <summary>
/// Called after the behavior is attached to an AssociatedObject.
/// </summary>
/// <remarks>
/// Override this to hook up functionality to the AssociatedObject.
/// </remarks>
protected override void OnAttached()
{
base.OnAttached();
// Hook events to change behavior
_expression = AssociatedObject.GetBindingExpression(TextBox.TextProperty);
AssociatedObject.TextChanged += OnTextChanged;
}
/// <summary>
/// Called when the behavior is being detached from its AssociatedObject, but before it has actually occurred.
/// </summary>
/// <remarks>
/// Override this to unhook functionality from the AssociatedObject.
/// </remarks>
protected override void OnDetaching()
{
base.OnDetaching();
// Un-hook events
AssociatedObject.TextChanged -= OnTextChanged;
_expression = null;
}
/// <summary>
/// Updates the source property when the text is changed.
/// </summary>
private void OnTextChanged(object sender, EventArgs args)
{
_expression.UpdateSource();
}
}
}
Ésta es básicamente una versión limpia en marcha de el código Microsoft Prism 4.1 (vea el proyecto Silverlight \ Prism.Interactivity si desea explorar el resto).
Ahora, ¿cómo se usa:
- agregar una referencia al ensamblaje System.Windows.Interactivity a su proyecto de Windows Phone.
- En cada página en la que desea utilizar el comportamiento, agregue una referencia a la asamblea XAML: xmlns: i = "CLR-espacio de nombres: System.Windows.Interactivity; montaje = System.Windows.Interactivity"
en el interior del XAML de cada cuadro de texto al que desea aplicar el bahvior (que ya cuenta con la unión a su propiedad de origen de un TwoWay), añada lo siguiente:
< i: Interaction.Behaviors>
< mi: UpdateTextBindingOnPropertyChanged />
< /i:Interaction.Behaviors>
Nota: el prefijo "mi:" puede ser diferente en su código. Es solo la referencia del espacio de nombres donde agregó la clase de comportamiento.
mismo tema en WP8, @StefanWick respuesta resuelto por mí. –
Aquí puede encontrar una solución de trabajo actualizando el enlace en el evento TextChanged: http://stackoverflow.com/a/4833196/928955 – breigo