Skip to content

Instantly share code, notes, and snippets.

@worldbeater
Created March 31, 2019 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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