/// <summary>コンストラクタ。</summary>
 /// <summary>コンストラクタ</summary>
 /// <param name="treeItem">TreeViewItem の元データを表すobject。</param>
 /// <param name="parentViewModel">このViewModelの親を表すNavigationTreeViewModel。</param>
 /// <param name="categoryType">カテゴリの種類を表す列挙型の内の1つ。。</param>
 public TreeViewItemViewModel(string treeItem,
                              NavigationTreeViewModel parentViewModel,
                              TreeNodeCategoryType categoryType)
     : this(treeItem, parentViewModel)
 {
     this.nodeCategory = categoryType;
 }
Exemple #2
0
        /// <summary>ツリー構造を作成してルートノードを返します。</summary>
        /// <param name="appData">アプリのデータを表すWpfTestAppData。</param>
        /// <param name="parent">TreeViewItemViewModelの親を表すNavigationTreeViewModel。</param>
        /// <returns>作成したツリー構造のルートノードを表すTreeViewItemViewModel。</returns>
        internal static TreeViewItemViewModel Create(WpfTestAppData appData, NavigationTreeViewModel parent)
        {
            var rootNode      = new TreeViewItemViewModel(appData.Student, parent);
            var physicalClass = new TreeViewItemViewModel("身体測定", parent, TreeNodeCategoryType.Physical);

            rootNode.Children.Add(physicalClass);

            foreach (var item in appData.Physicals)
            {
                var child = new TreeViewItemViewModel(item, parent);
                physicalClass.Children.Add(child);
            }

            var testPointClass = new TreeViewItemViewModel("試験結果", parent, TreeNodeCategoryType.TestPoint);

            rootNode.Children.Add(testPointClass);

            foreach (var item in appData.TestPoints)
            {
                var child = new TreeViewItemViewModel(item, parent);
                testPointClass.Children.Add(child);
            }

            return(rootNode);
        }
        /// <summary>コンストラクタ</summary>
        /// <param name="treeItem">TreeViewItem の元データを表すobject。</param>
        /// <param name="parentViewModel">このViewModelの親を表すNavigationTreeViewModel。</param>
        public TreeViewItemViewModel(object treeItem, NavigationTreeViewModel parentViewModel)
        {
            this.parent   = parentViewModel;
            this.Children = new ReactiveCollection <TreeViewItemViewModel>()
                            .AddTo(this.disposables);

            this.SourceData = treeItem;
            var imageFileName = string.Empty;

            switch (this.SourceData)
            {
            case PersonalInformation p:
                this.ItemText = p.ObserveProperty(x => x.Name)
                                .ToReadOnlyReactivePropertySlim()
                                .AddTo(this.disposables);

                imageFileName = "user.png";
                break;

            case PhysicalInformation ph:
                this.ItemText = ph.ObserveProperty(x => x.MeasurementDate)
                                .Select(d => d.HasValue ? d.Value.ToString("yyy年MM月dd日") : "新しい測定")
                                .ToReadOnlyReactivePropertySlim()
                                .AddTo(this.disposables);

                imageFileName = "heart.png";
                break;

            case TestPointInformation t:
                this.ItemText = t.ObserveProperty(x => x.TestDate)
                                .ToReadOnlyReactivePropertySlim()
                                .AddTo(this.disposables);

                imageFileName = "test.png";
                break;

            case string s:
                this.ItemText = this.ObserveProperty(x => x.SourceData)
                                .Select(v => v as string)
                                .ToReadOnlyReactivePropertySlim()
                                .AddTo(this.disposables);

                if (s == "身体測定")
                {
                    imageFileName = "physical_folder.png";
                }
                else if (s == "試験結果")
                {
                    imageFileName = "test_folder.png";
                }
                break;
            }

            var img = new System.Windows.Media.Imaging.BitmapImage(
                new Uri("pack://application:,,,/NavigationTree;component/Resources/" + imageFileName,
                        UriKind.Absolute));

            this.ItemImage = new ReactiveProperty <System.Windows.Media.ImageSource>(img)
                             .AddTo(this.disposables);

            this.IsExpanded = new ReactivePropertySlim <bool>(true)
                              .AddTo(this.disposables);
            this.IsSelected = new ReactivePropertySlim <bool>(false)
                              .AddTo(this.disposables);
            this.IsCategory = new ReactivePropertySlim <bool>(this.SourceData != null && this.SourceData is string)
                              .AddTo(this.disposables);

            this.AddNewDataCommand = new List <IObservable <bool> >()
            {
                this.IsCategory,
                this.IsSelected
            }
            .CombineLatestValuesAreAllTrue()
            .ToReactiveCommand()
            .AddTo(this.disposables);
            this.AddNewDataCommand.Subscribe(() => this.addNewItem());
        }