Problem with Bindind + Keydown C# WPF

Asked

Viewed 30 times

1

I have in XAML a combobox and a textbox, being them:

                <Label Grid.ColumnSpan="4" Content="Tipo Filtro" Grid.Column="0"  Grid.Row="0" Padding="0" VerticalContentAlignment="Center"/>
                <ComboBox SelectedValue="{Binding Path=TipoFiltroSQL, Mode = TwoWay}" Name="CmbTipoFiltro" Margin="5" Grid.ColumnSpan="4"  Grid.Column="0"  Grid.Row="1" Padding="0" VerticalContentAlignment="Center"/>
                <Label Grid.ColumnSpan="16" Content="Filtro" Grid.Column="4"  Grid.Row="0" Padding="0" VerticalContentAlignment="Center"/>
                <TextBox Name="TextFiltro" Text = "{Binding Path=FiltroConsulta, Mode = TwoWay}" Margin="5" Grid.ColumnSpan="16"  Grid.Column="4"  Grid.Row="1" Padding="0" VerticalContentAlignment="Center" KeyUp="FiltroTextChangedEventHandler" />

Note that right now I’m using Keyup to capture the key, but I’ve tried several other things.

And the Filtrotextchangedeventhandler method:

private void FiltroTextChangedEventHandler(object sender, KeyEventArgs e)
    {
        Console.WriteLine("Valor TexBox: " + TextFiltro);
        Console.WriteLine("Tipo Consulta: "+Bean.TipoFiltroSQL);
        Console.WriteLine("Valor: " + Bean.FiltroConsulta);
        Bean.CarregaListaFiltro();
        Console.WriteLine("Cliente Localizados: " + Bean.Lista.Count);
        updateDataContext();
    }

In the case that textbox is bound with the following String:

public String FiltroConsulta { get; set; }

When I type any character it appears in the textbox and then it is deleted, in the console appears the following situation:

Valor TexBox: System.Windows.Controls.TextBox: p
Tipo Consulta: INICIA_COM
Valor: 
Cliente Localizados: 3

in updateDataContext I do the following:

private void updateDataContext()
    {
        this.DataContext = null;
        this.DataContext = Bean;
    }

note that the letter "P" is in the textbox, however the value with the string with Binding appears empty, someone can tell me why?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.