// コンストラクタ public SupplyViewModel() { // 設定ファイルに記録していた情報を書き戻す { if (SettingsStore.MemoryWindowPositionFlg) { WindowPositionLeft.Value = SettingsStore.SupplyWindowRect[0]; WindowPositionTop.Value = SettingsStore.SupplyWindowRect[1]; WindowPositionWidth.Value = SettingsStore.SupplyWindowRect[2]; WindowPositionHeight.Value = SettingsStore.SupplyWindowRect[3]; } AutoOpenWindowFlg.Value = SettingsStore.AutoSupplyWindowFlg; } // 画面の位置が変更された際、自動で設定ファイルに書き戻すようにする WindowPositionLeft.Subscribe(x => { if (!SettingsStore.MemoryWindowPositionFlg) { return; } SettingsStore.SupplyWindowRect[0] = x; SettingsStore.ChangeSettingFlg = true; }); WindowPositionTop.Subscribe(x => { if (!SettingsStore.MemoryWindowPositionFlg) { return; } SettingsStore.SupplyWindowRect[1] = x; SettingsStore.ChangeSettingFlg = true; }); WindowPositionWidth.Subscribe(x => { if (!SettingsStore.MemoryWindowPositionFlg) { return; } SettingsStore.SupplyWindowRect[2] = x; SettingsStore.ChangeSettingFlg = true; }); WindowPositionHeight.Subscribe(x => { if (!SettingsStore.MemoryWindowPositionFlg) { return; } SettingsStore.SupplyWindowRect[3] = x; SettingsStore.ChangeSettingFlg = true; }); // 起動時にこの画面を表示するか? AutoOpenWindowFlg.Subscribe(value => { SettingsStore.AutoSupplyWindowFlg = value; }); // 表示する資材のモードに対応してボタンの色・表示内容を変える SupplyModeButtonColor = ShowSupplyMode.Select(x => { return((Brush)(x == 0 ? new SolidColorBrush(Colors.Pink) : new SolidColorBrush(Colors.SkyBlue))); }).ToReadOnlyReactiveProperty(); SupplyModeButtonContent = ShowSupplyMode.Select(x => { return(x == 0 ? "通常資材" : "特殊資材"); }).ToReadOnlyReactiveProperty(); // その他staticな初期化 GraphPeriodList = new ReactiveProperty <List <string> >(graphPeriodDic.Keys.Select(p => p).ToList()); // 表示期間・資材モードが変更された際、グラフを再描画する SupplyGraphModel = GraphPeriodIndex.CombineLatest(ShowSupplyMode, (_, mode) => RedrawSupplyGraph()).ToReactiveProperty(); // コマンドを設定 ChangeSupplyModeCommand.Subscribe(_ => { ShowSupplyMode.Value = (ShowSupplyMode.Value == 0 ? 1 : 0); RedrawSupplyGraph(); }); SaveSupplyGraphCommand.Subscribe(_ => SupplyModel.SaveSupplyGraph(SupplyGraphModel.Value)); ShowEditorCommand.Subscribe(_ => { var vm = new SupplyEditorViewModel(); var view = new Views.SupplyEditorView { DataContext = vm }; view.ShowDialog(); }); // タイマーを指定してグラフ更新を定期実行する var timer = new Timer(1000 * 60 * 5); timer.Elapsed += (sender, e) => { try { timer.Stop(); RedrawSupplyGraph(); } finally { timer.Start(); } }; timer.Start(); // まず最初の画面更新を掛ける SupplyGraphModel.Value = RedrawSupplyGraph(); }