public override void OnApplyTemplate() { EditButton = GetTemplateChild("EditButton") as ButtonBase; setValueCommand.DistinctUntilChanged().Subscribe(a => { Value = Main.Equals(a); RaiseToggleEvent(Value ? Main : Alternate, Value); }); base.OnApplyTemplate(); }
/// <summary> /// コンストラクタ /// </summary> /// <param name="source">関連付けるWebImageオブジェクト</param> /// <param name="visionApiSubscriptionKey">Microsoft Vision API のSubscription Key</param> /// <param name="logger">ログメッセージ通知オブジェクト</param> public WebImageViewModel(WebImage source, string visionApiSubscriptionKey, ILogger logger) { this.source = source; this.logger = logger; this.visionApiSubscriptionKey = visionApiSubscriptionKey; //Model(WebImage)のプロパティをReactivePropertyに変換 Thumbnail = source.ObserveProperty(x => x.Thumbnail).ToReadOnlyReactiveProperty(); DisplayImage = source.ObserveProperty(x => x.DisplayImage).ToReadOnlyReactiveProperty(); Overlay = source.ObserveProperty(x => x.Overlay).ToReadOnlyReactiveProperty(); SourceUrl = source.ObserveProperty(x => x.SourceUrl).ToReadOnlyReactiveProperty(); SourceTitle = source.ObserveProperty(x => x.SourceTitle).ToReadOnlyReactiveProperty(); ImageProperty = source.ObserveProperty(x => x.ImageProperty).ToReadOnlyReactiveProperty(); //実行中フラグ IsProcessing = progress.IsProcessingObservable.StartWith(false) .ToReadOnlyReactiveProperty(); //プログレスバーの表示切替 - 実行中のみ表示する ProgressVisibility = IsProcessing .Select(x => x ? Visibility.Visible : Visibility.Collapsed) .ToReadOnlyReactiveProperty(); //画像のサイズ変更時に実行するコマンド SizeChangedCommand = new ReactiveCommand<Size>(); SizeChangedCommand .DistinctUntilChanged() .Throttle(TimeSpan.FromMilliseconds(200)) .Subscribe(size => { //現在のサイズで 顔領域の矩形を再描画 source.DrawFaceRect(size); //最新のサイズを保存しておく ⇒画像再選択時に使う imageSize = size; }) .AddTo(disposables); //リンク元ページURLのハイパーリンククリック時 NavigateCommand = new ReactiveCommand(); NavigateCommand.Subscribe(_ => { Process.Start(source.SourceUrl); }).AddTo(disposables); }