ian turner

ian turner

  • 2.1k
  • 94
  • 641

Problem with Binding to background class property

Jul 28 2021 2:53 PM

I have a screen with multiple DataGrids, and each has a header line with total records etc above it.
My problem is that my XAML will NOT read  the data from the background class, although debugging show it updating the values with the Setter as expected, but the getter is never called

To clarify the scenario, the current setup is :
        XAML file :-
        <!--Keys to access the background data classes-->
        <local:Nwcustomer  x:Key="CustDb"/>
        <local:Nworder  x:Key="OrderDb"/>
        <local:Nworderdetails  x:Key="OrderDetailsDb"/>
        <local:Nwcategory x:Key="CategoryDb"/>

The above have no errors at all on them, so are presumably correct..

The offending control is :

            <TextBlock x:Name="CustomersTot"
                DataContext="{Binding CustDb}"
                Text="{Binding CustomersTotal , UpdateSourceTrigger=PropertyChanged}"
                 Foreground="{StaticResource Black1}"/>

There are 3 dots ... under the "CustB" in DataContext, reporting "Member not found in data context 'NwCustomer'"
Equally, the ... under CustomerTotal in the Text= line say the same : "Member not found in data context 'NwCustomer'"

I have even tried removing the Propertychanged from the binding.  Still no change in operation.

When debugging the App The CustomersCurrent Property Setter is triggered by the line :
    nwcustomer . CustomerCurrent = CustomersGrid . SelectedIndex; in the Cs file
and if I use  a CW after the values are set in t e CS file, they work correctly, and the GETTER is called as expected.

It is just that the TextBlock will NOT do it in XAML, but filling the TextBox field in Code Behind works perfectly.

This is drivng me crazy, I have a couple of other similar fields, all are having the same issue.

Answers (1)