public static ItineraryElementViewModel CreateViewModel(ItineraryElement model) { switch (model) { case TransportElement transportElement: return(new TransportElementViewModel(transportElement)); case PeriodElement periodElement: return(new PeriodElementViewModel(periodElement)); case ItineraryElement itineraryElement: return(new ItineraryElementViewModel(itineraryElement)); default: throw new InvalidOperationException("ViewModelが実装されていない型が読み込まれました"); } }
public ItineraryElementViewModel(ItineraryElement model) { Color = model.ObserveProperty(m => m.Color).ToReactiveProperty(); FreeForm = model.ObserveProperty(m => m.FreeForm).ToReactiveProperty(); Icon = model.ObserveProperty(m => m.Icon).ToReactiveProperty(); FreeForm.Subscribe(x => model.FreeForm = x).AddTo(Disposables); Color.Subscribe(x => model.Color = x).AddTo(Disposables); Icon.Subscribe(x => model.Icon = x).AddTo(Disposables); RemoveElementCommand = new ReactiveCommand(); RemoveElementCommand.Subscribe(model.RemoveElement); MoveUpElementCommand = new ReactiveCommand(); MoveUpElementCommand.Subscribe(model.MoveUpElement); MoveDownElementCommand = new ReactiveCommand(); MoveDownElementCommand.Subscribe(model.MoveDownElement); }