public MainViewModel()
        {
            // テストデータ
            var thm = "ガソリン急落 半年ぶり143円台";

            ThemeList.Add(new ThemeModel(thm, "経済", _rdm.Next(1, 3), _rdm.Next(0, 3)));
            ThemeList[ThemeList.Count - 1].ContentList.Add(new ContentModel("レギュラーガソリン急落、前週比2.9円安の143.5円 半年ぶりの安値", "記事", $"{_rdm.Next(15, 45)}行", thm));
            ThemeList[ThemeList.Count - 1].ContentList.Add(new ContentModel("[ハイオクガソリン実売価格(「e燃費」調べ)]", "画像", "1920x1080", thm));
            thm = "新型コロナの影響拡大を受けて";
            ThemeList.Add(new ThemeModel("新型コロナの影響拡大を受けて", "政治", _rdm.Next(1, 3), _rdm.Next(0, 3)));
            ThemeList[ThemeList.Count - 1].ContentList.Add(new ContentModel("公共料金の支払いを猶予 欧州から入国、待機要請 新型コロナ", "記事", $"{_rdm.Next(15, 45)}行", thm));
            ThemeList[ThemeList.Count - 1].ContentList.Add(new ContentModel("電気など公共料金支払い猶予要請へ 欧州など38カ国に入国制限", "記事", $"{_rdm.Next(15, 45)}行", thm));
            ThemeList[ThemeList.Count - 1].ContentList.Add(new ContentModel("新型コロナウイルス感染症対策本部", "画像", "355x466", thm));
            thm = "新型iPad、25日に発売";
            ThemeList.Add(new ThemeModel("新型iPad、25日に発売", "社会", _rdm.Next(1, 3), _rdm.Next(0, 3)));
            ThemeList[ThemeList.Count - 1].ContentList.Add(new ContentModel("アップル、LiDARセンサー/2カメラの新iPad Pro。トラックパッドにも初対応", "記事", $"{_rdm.Next(15, 45)}行", thm));
            ThemeList[ThemeList.Count - 1].ContentList.Add(new ContentModel("新型iPad、25日に発売 米アップル、超広角カメラ搭載", "記事", $"{_rdm.Next(15, 45)}行", thm));
            ThemeList[ThemeList.Count - 1].ContentList.Add(new ContentModel("iPad(アイパッド)プロ", "画像", "400x448", thm));
            thm = "将棋の清水市代女流六段が史上初の女流七段に";
            ThemeList.Add(new ThemeModel("将棋の清水市代女流六段が史上初の女流七段に", "社会", _rdm.Next(1, 3), _rdm.Next(0, 3)));
            ThemeList[ThemeList.Count - 1].ContentList.Add(new ContentModel("清水が史上初の女流七段に 里見は女流六段昇段", "記事", $"{_rdm.Next(15, 45)}行", thm));
            ThemeList[ThemeList.Count - 1].ContentList.Add(new ContentModel("女流七段への昇段は史上初", "記事", $"{_rdm.Next(15, 45)}行", thm));
            ThemeList[ThemeList.Count - 1].ContentList.Add(new ContentModel("日本将棋連盟", "画像", "1280x720", thm));
            thm = "【第1部】日経平均株価";
            ThemeList.Add(new ThemeModel("【第1部】日経平均株価", "経済", _rdm.Next(1, 3), _rdm.Next(0, 3)));
            ThemeList[ThemeList.Count - 1].ContentList.Add(new ContentModel("乱高下後に小幅続落=不安定な値動き続く", "記事", $"{_rdm.Next(15, 45)}行", thm));
            ThemeList[ThemeList.Count - 1].ContentList.Add(new ContentModel("日経平均は急速に切り返し底入れを期待", "記事", $"{_rdm.Next(15, 45)}行", thm));
            ThemeList[ThemeList.Count - 1].ContentList.Add(new ContentModel("ダウ工業株30種平均が過去最大の下げ幅", "画像", "1920x1080", thm));

            ContentList = new ObservableCollection <ContentModel>(ThemeList.SelectMany(theme => theme.ContentList).ToList());

            thm = "";
            ContentFreeList.Add(new ContentModel("【コロナショックで資産が半分に!?】「iDeCo・つみたてNISA」利用者が今とるべき対処法とは", "記事", $"{_rdm.Next(15, 45)}行", thm));
            ContentFreeList.Add(new ContentModel("東電、全社員に一時金9万円 初任給は3千円上げ", "画像", $"{_rdm.Next(600, 1980)}x{_rdm.Next(400, 1080)}", thm));
            ContentFreeList.Add(new ContentModel("死者64万人想定のコロナ緊急宣言は妥当なのか", "記事", $"{_rdm.Next(15, 45)}行", thm));
            ContentFreeList.Add(new ContentModel("自然災害リスクへの警戒高まる 川沿いの住宅地、公示地価で下落顕著", "記事", $"{_rdm.Next(15, 45)}行", thm));
            ContentFreeList.Add(new ContentModel("直ちに消費税率ゼロにする発想ない", "記事", $"{_rdm.Next(15, 45)}行", thm));
            ContentFreeList.Add(new ContentModel("NY株1700ドル超下げ 2万ドル割り込む 取引一時停止", "記事", $"{_rdm.Next(15, 45)}行", thm));
            ContentFreeList.Add(new ContentModel("18日東京株式市場終値 284円98銭安の1万6726円55銭", "画像", $"{_rdm.Next(600, 1980)}x{_rdm.Next(400, 1080)}", thm));
            ContentFreeList.Add(new ContentModel("USJが子ども達に『サプライズプレゼント』学童保育に通う3千人超に1300万円分", "記事", $"{_rdm.Next(15, 45)}行", thm));
            ContentFreeList.Add(new ContentModel("GPIF22兆円の大損失 株価暴落&運用失敗", "記事", $"{_rdm.Next(15, 45)}行", thm));

            // Drag&Drop
            this.Description           = new DropAcceptDescription();
            this.Description.DragOver += Description_DragOver;
            this.Description.DragDrop += Description_DragDrop;
        }
Пример #2
0
        /// <summary>
        /// Dropイベント
        /// </summary>
        /// <param name="args"></param>
        private void Description_DragDrop(System.Windows.DragEventArgs args)
        {
            if (args.Data.GetDataPresent(typeof(ContentModel)))
            {
                // Drop item
                var data = args.Data.GetData(typeof(ContentModel)) as ContentModel;

                // EventArgsからDrop先のFrameworkElementを取得
                var feDest = args.Source as System.Windows.Controls.ListBox;
                // EventArgsからDrop先のバインドオブジェクトを取得
                var bindDest = BindingOperations.GetBinding(
                    (args.Source as System.Windows.Controls.ListBox), System.Windows.Controls.ListBox.ItemsSourceProperty).Path.Path;

                // Drop元のバインドオブジェクトを取得
                var dragFromTheme = ThemeList.Any(item => item.ContentList.Contains(data));
                var dragFromFree  = ContentFreeList.Contains(data);

                // Drop元とDrop先のチェック
                if (bindDest == nameof(ThemeList))
                {
                    if (dragFromFree)
                    {
                        Point position = args.GetPosition(args.OriginalSource as IInputElement);
                        //System.Windows.Media.VisualTreeHelper.HitTest(
                        //    this
                        //                         , null
                        //                         , new System.Windows.Media.HitTestResultCallback(OnHitTestResultCallback)
                        //                         , new System.Windows.Media.PointHitTestParameters(position));
                        // Drop Index
                        //var targetContainer = GuiUtils.GetTemplatedRootElement(args.OriginalSource as FrameworkElement);
                        //var targetContainer2 = GuiUtils.FindAncestor<System.Windows.Controls.ListBox>(args.OriginalSource as FrameworkElement);
                        var index = ThemeList.IndexOf(DropTarget);
                        index = index < 0 ? feDest.Items.Count - 1 : index;
                        //var datas =
                        ThemeList[index].ContentList.Add(data);
                        ContentFreeList.Remove(data);
                    }
                    else if (dragFromTheme)
                    {
                        return;
                    }
                }
                else if (bindDest == nameof(ContentFreeList))
                {
                    if (dragFromFree)
                    {
                        // Drop Index
                        var targetContainer = GuiUtils.GetTemplatedRootElement(args.OriginalSource as FrameworkElement);
                        var index           = feDest.ItemContainerGenerator.IndexFromContainer(targetContainer);
                        index = index < 0 ? feDest.Items.Count - 1 : index;
                        // Collectionに反映
                        var ocDest = this[bindDest] as ObservableCollection <ContentModel>;
                        ocDest.Move(feDest.SelectedIndex, index);
                    }
                    else if (dragFromTheme)
                    {
                        // Drop Index
                        var index = ThemeList
                                    .Select((thm, i) => new { Theme = thm, Index = i })
                                    .Where(item => item.Theme.ContentList.Contains(data))
                                    .Select(item => item.Index).FirstOrDefault();

                        // Collectionに反映
                        ContentFreeList.Add(data);
                        ThemeList[index].ContentList.Remove(data);
                    }
                }
                return;
            }
            if (args.Data.GetDataPresent(typeof(ThemeModel)))
            {
                return;
            }
        }