Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

171
Visualizações
Really trivial WPF Binding refuses to work

Data Binding is supposed to be the CENTRE OF FOCUS and even the "Raison d'etre" of apps written using WPF, but sadly the Binding in my really simple test of it as shown below simply DOES NOT WORK.... and so far, nobody can seem to tell me why it does not work. It started in my main code base, so in trying to debug the problem, I have created this trivial window (named "bindingtest") that has a similar Customers DataGrid that is populated from an Sql Db. The ItemsSource Binding for that works just fine.

Above the Grid I have a Status line showing Db Name, Total records, and (if it worked) the currently selected record in the datagrid. Pretty simple stuff eh ?

Basically the Currently selected item is a simple TextBlock with its .Text bound to a FULL property in the codebehind file, which of course fully supports PropertyChanged(). (Shown in image below).

    private int customersTotal;
    public int CustomersTotal
    {
        {return customersTotal; }
        set {customersTotal = value;
            OnPropertyChanged ( nameof ( CustomersTotal ) );}
    }

The Window and XAML root file names are "bindingtest" The binding specified below of "BindTest" is declared in of the XAML and shows no errors (like the '...' under BindTest) so clearly recognises the source of "bindingtest ? as being a valid DataContext.

<local:bindingtest x:Key="BindTest"/>

Here is the pretty trivial TextBlock that is a part of the Status line but which refuses to call the Getter for the Property "CustomerCurrent" in XAML Note the hover information !! CustomerCurrent is in this files code behind file...

enter image description here

Also, I have tried using the SAME Datacontext=this; in codebehind - same NON Result. Property Getter is still never called. The Property is set via the line below in the Grid.SelectionChanged event handler for the Datagrid in codebehind by :

int newsel = CustomersGrid. SelectedIndex;
// Update the problem property !!
CustomerCurrent = newsel;

This works correctly, and the Getter for CurrentCustomer is called as expected, and the value is changed as relevant.

I have tried every possible option foud onthe internet forums etc, but NOTHING works, it stubbornly refuses to call the "CustomerCurrent" Property Getter and update the Text of the TexBlock on the screen.

For background, I have used Value Converters in this window on a more complex example of this testing window, and they work just fine, so some binding does work, just not this most tirvial of examples.

CAN AYONE PLEASE TELL ME WHY THIS DOES NOT WORK ?? I am going totally mad.

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda