Xamarin Forms ReactiveUI
代码:
文件: MainPageViewModel.cs
using System.Reactive; using ReactiveUI; using ReactiveUI.Fody.Helpers; namespace App2 { public class MainPageViewModel: ReactiveObject { public ReactiveCommand<Unit, Unit> OnChange { get; } [Reactive] public string Greeting { get; set; } public MainPageViewModel() { Greeting = "Hello world!"; OnChange = ReactiveCommand.Create(() => { Greeting = "Go C#!"; }); } } }
页面:
文件: MainPage.xaml
<?xml version="1.0" encoding="utf-8" ?> <xamForms:ReactiveContentPage x:TypeArguments="vm:MainPageViewModel" xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:xamForms="clr-namespace:ReactiveUI.XamForms;assembly=ReactiveUI.XamForms" xmlns:vm="clr-namespace:App2;assembly=App2" x:Class="App2.MainPage"> <ContentPage.BindingContext> <vm:MainPageViewModel></vm:MainPageViewModel> </ContentPage.BindingContext> <StackLayout> <Label Text="{Binding Greeting}" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" /> <Button Command="{Binding OnChange}" Text="Click"></Button> </StackLayout> </xamForms:ReactiveContentPage>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论