代码之家  ›  专栏  ›  技术社区  ›  David Huthaifah Kholi

从MVVM到Xamarin主页的消息中心

  •  0
  • David Huthaifah Kholi  · 技术社区  · 7 年前

    MessagingCentre Xamarin

    MainPage.xaml.cs MessageCentre ,查找“focus”消息,然后将窗体的焦点设置为一个名为txtfirstname的条目控件。

    public MainPage()
        {
            InitializeComponent();
            BindingContext = new ViewModel();
    
            MessagingCenter.Subscribe<MainPage>(this, "Focus", (sender) => { txtFirstName.Focus(); });
        }
    

     private void ClearFormCommand(object obj)
    {
        FirstName = string.Empty;
        Surname = string.Empty;
        Age = string.Empty;
        AboutMe = string.Empty;
    
        MessagingCenter.Send<MainPage>(this, "Focus");
    }
    

    this MessagingCentre.Send

    MainPage

    2 回复  |  直到 7 年前
        1
  •  0
  •   Csharpest    7 年前

    <MainPage> ViewModel

        2
  •  0
  •   Mukesh Kumar    7 年前

    首先, messagingcenter.send(this,“focus”);

    有关信息中心的更多信息,您可以阅读 here

    希望这对你有帮助。

    推荐文章