Skip to content

Instantly share code, notes, and snippets.

@worldbeater
Created March 31, 2019 13:00
Show Gist options
  • Save worldbeater/99646eb2b972902b423441f9e296c321 to your computer and use it in GitHub Desktop.
Save worldbeater/99646eb2b972902b423441f9e296c321 to your computer and use it in GitHub Desktop.
public partial class FeedbackView : Form, IViewFor<FeedbackViewModel>
{
public FeedbackView()
{
InitializeComponent();
ViewModel = new FeedbackViewModel(new WinFormsSender(), new Clock());
this.WhenActivated(subscriptions =>
{
this.Bind(ViewModel, x => x.Title, x => x.TitleTextBox.Text)
.DisposeWith(subscriptions);
this.OneWayBind(ViewModel, x => x.TitleLengthMax, x => x.TitleTextBox.MaxLength)
.DisposeWith(subscriptions);
this.WhenAnyValue(x => x.ViewModel.TitleLength, x => x.ViewModel.TitleLengthMax)
.Select(values => $"{values.Item1} letters used from {values.Item2}")
.BindTo(this, x => x.TitleLengthLabel.Text)
.DisposeWith(subscriptions);
this.BindCommand(ViewModel, x => x.Submit, x => x.SubmitButton)
.DisposeWith(subscriptions);
// Several lines of code are deliberately omitted for brevity, browse full project
// sources at: https://github.com/worldbeater/ReactiveMvvm
});
}
public FeedbackViewModel ViewModel { get; set; }
object IViewFor.ViewModel
{
get => ViewModel;
set => ViewModel = (FeedbackViewModel)value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment