Search code examples
mvvmbindinguwpcross-platformmvvmcross

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");            
    }    
}

Solution

  • Try this:

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