0

I have some WPF control called Foo. Grid structure with DevExpress LoadingDecorator looks like that:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="60" />
    </Grid.RowDefinitions>

    <StackPanel Grid.Row="0">
        <dx:LoadingDecorator Name="Decorator" IsSplashScreenShown="{Binding Path=ShowLoader}" SplashScreenLocation="CenterWindow">
            <dx:LoadingDecorator.SplashScreenTemplate>
                <DataTemplate>
                    <dx:WaitIndicator DeferedVisibility="True">
                        <dx:WaitIndicator.ContentTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Vertical">
                                    <TextBlock Text="Operation:" FontSize="15"/>
                                    <TextBlock Text="{Binding Path=CurrLoadStat}"/>
                                </StackPanel>
                            </DataTemplate>
                        </dx:WaitIndicator.ContentTemplate>
                    </dx:WaitIndicator>
                </DataTemplate>
            </dx:LoadingDecorator.SplashScreenTemplate>
        </dx:LoadingDecorator>
    </StackPanel>

    ...

</Grid>

Base ViewModel class implements INotifyPropertyChanged interface and ViewModel class (FooViewModel) used as DataContext for control with Grid described above inherits from it. I have implemented property to change text property in 2nd TextBlock element:

        private string currLoadStat = "Preparing data...";

        public string CurrtLoadStat
        {
            get
            {
                return currLoadStat;
            }
            set
            {
                currLoadStat = value;
                OnPropertyChanged("CurrLoadStat");
            }
        }

My problem is that binding instruction doesn't work and I see only text defined in first TextBlock. Can You provide me some solution to resolve this problem?

Maciej S.
  • 752
  • 10
  • 22

1 Answers1

2

Your property has a "t" in the middle of the name but your binding path (XAML) and magic string you pass to OnPropertyChanged do not. The string you pass when you raise the PropertyChanged event method must exactly match your view model's property name.

If you are using C# 5 or 6 then switch to using one of the approaches outlined here and you would eliminate the need for passing magic strings.

Community
  • 1
  • 1
blins
  • 2,515
  • 21
  • 32
  • Does the run time output window show a binding error? What if you temporarily change to just `... Text={Binding }`, does anything show up in the Textblock then? That would rule out that the issue is not the Path. – blins Jun 28 '16 at 12:34
  • Error from output window: "System.Windows.Data Error: 40 : BindingExpression path error: 'CurrLoadStat' property not found on 'object' ''String' (HashCode=-860452824)'. BindingExpression:Path=CurrLoadStat; DataItem='String' (HashCode=-860452824); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')" . Changing binding to Text={Binding} only gives me text "Loading..." taken from DevExpress properties. – Maciej S. Jun 28 '16 at 14:30
  • The output tells you one thing for sure which is that the DataContext or your TextBlock is not an instance of your view model class but rather just a string (set to "Loading..." as you mentioned). – blins Jun 29 '16 at 01:06
  • Yes, DataContext was not properly defined. Thank You for give me right direction of thinking. :) – Maciej S. Jul 01 '16 at 07:40