Problem with Bindind + KeyDown C # WPF

1

I have in XAML a combobox and a textbox, they are:

                <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 I am currently using KeyUp to pick up the key, but I have already tried several other things.

And the FilterTextChangedEventHandler 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 case this 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, the following situation appears in the console:

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

In the updateDataContext I do the following:

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

Note that the letter "P" is in the textbox, but the value with the string with the binding appears empty, can anyone tell me why?

    
asked by anonymous 28.12.2018 / 19:38

0 answers