1 using System;
2 using System.Reactive.Disposables;
3 using System.Reactive.Linq;
4 using Reactive.Bindings.Binding;
5 using Reactive.Bindings.Extensions;
6 using TrainEditor2.Extensions;
7 using TrainEditor2.ViewModels.Panels;
8 
9 namespace TrainEditor2.Views
10 {
11 	public partial class FormEditor
12 	{
BindToScreen(ScreenViewModel y)13 		private IDisposable BindToScreen(ScreenViewModel y)
14 		{
15 			CompositeDisposable screenDisposable = new CompositeDisposable();
16 
17 			y.Number
18 				.BindTo(
19 					numericUpDownScreenNumber,
20 					z => z.Value,
21 					BindingMode.TwoWay,
22 					null,
23 					z => (int)z,
24 					Observable.FromEvent<EventHandler, EventArgs>(
25 							h => (s, e) => h(e),
26 							h => numericUpDownScreenNumber.ValueChanged += h,
27 							h => numericUpDownScreenNumber.ValueChanged -= h
28 						)
29 						.ToUnit()
30 				)
31 				.AddTo(screenDisposable);
32 
33 			y.Number
34 				.BindToErrorProvider(errorProvider, numericUpDownScreenNumber)
35 				.AddTo(screenDisposable);
36 
37 			y.Layer
38 				.BindTo(
39 					numericUpDownScreenLayer,
40 					z => z.Value,
41 					BindingMode.TwoWay,
42 					null,
43 					z => (int)z,
44 					Observable.FromEvent<EventHandler, EventArgs>(
45 							h => (s, e) => h(e),
46 							h => numericUpDownScreenLayer.ValueChanged += h,
47 							h => numericUpDownScreenLayer.ValueChanged -= h
48 						)
49 						.ToUnit()
50 				)
51 				.AddTo(screenDisposable);
52 
53 			return screenDisposable;
54 		}
55 	}
56 }
57