C-Jay
C-Jay

Reputation: 681

UWP MVVMCross bind property to method

How do I change the content of the second button, based on the method from the first button with MVVPCross?

Something like this:

MainPage.xaml:

<Button Content="Translate" Click="{x:Bind PhonewordTranslator.Translate}" />
<Button Content="{x:Bind PhonewordTranslatorViewModel.CallButtonText, Mode=TwoWay}" Click="{x:Bind PhonewordTranslatorViewModel.Call}" />

PhonewordTranslatorViewModel.cs:

public class PhonewordTranslatorViewModel : MvxViewModel
{
    ...
    private string _callButtonText;
    public string CallButtonText { get=>_callButtonText; set=>SetProperty(ref _callButtonText, value); }

    public void Translate()
    {
        SetProperty(ref _callButtonText, "test123");            
    }    
}

Upvotes: 1

Views: 107

Answers (2)

user1419778
user1419778

Reputation: 92

Try this:

 public void Translate()
{
  CallButtonText = "NewText"; 
  RaisePropertyChanged(() => CallButtonText);     
}  

Upvotes: 1

Dishant
Dishant

Reputation: 1595

Please modify your translate method as below:

 public void Translate()
 {
    CallButtonText = "test123";            
 }  

Upvotes: 0

Related Questions