0

I'm new on Caliburn.Micro.

The Binding a text on TextBlock.

The text of TextBlock is changed on start up or initialize on ViewModel,

But it would not change in fired function.

I don't know why for a day.

I need any help badly.

Here is code what i wrote.

In View

<TextBlock Grid.Row="0" FontSize="72" Foreground="White" 
    HorizontalAlignment="Center"  VerticalAlignment="Center"
    x:Name="DisplayedPhoneNumber"/>

In ViewModel

    //! Scren Binding.
    public string DisplayedPhoneNumber { get; set; } ="0103214321";

When i press a button on view, i call a function like this,

In View

<Border  Style="{StaticResource StyleNumberKeyBorder}">
    <Button Content="1" Style="{StaticResource StyleNumberKeyButton}"
        cal:Message.Attach="[Event Click]=[Action CmdNumberClick(1)]"/>
</Border>

In ViewModel, CmdNumberClick function like this...

    public void CmdNumberClick(string pressed_number)
    {
        DisplayedPhoneNumber = "plz change...";
    }

I check the fired function, and checked DisplayedPhoneNumber is changed, But TextBlck was not changed.

Please help.

sharp
  • 1,191
  • 14
  • 39
Jake
  • 129
  • 10

1 Answers1

1

public string DisplayedPhoneNumber { get; set; }

needs to be

private string _displayedPhoneNumber;
public string DisplayedPhoneNumber{
   get{ return _displayedPhoneNumber;}
   set{
      _displayedPhoneNumber = value;
      NotifyOfPropertyChanged(() => DisplayedPhoneNumber);
    }
}

Associated ViewModel has to inherit PropertyChangedBase or a base class that derives INotifyPropertyChanged;

mvermef
  • 3,814
  • 1
  • 23
  • 36
  • Could use nameof instead of ()=>DisplayedPhoneNumber while using NotifyOfPropertyChange. NotifyOfPropertyChanged(nameof(DisplayedPhoneNumber)); – Anu Viswan Feb 15 '18 at 05:15
  • considering that didn't exist in the framework till recently the syntax of my set is correct for the implementation CM uses. – mvermef Feb 15 '18 at 05:23