Пример #1
0
        public PinBoard(IBioLinkPlugin owner)
        {
            this.Owner = owner;
            InitializeComponent();
            this.DataContext        = _model;
            lvw.ItemsSource         = _model;
            lvw.MouseRightButtonUp += new MouseButtonEventHandler((s, e) => { ShowPopupMenu(); });
            lvw.MouseDoubleClick   += new MouseButtonEventHandler((s, e) => { PerformDefaultCommand(); });
            this.AllowDrop          = true;

            _dragHelper = new ListViewDragHelper(lvw, CreateDragData);

            // this.GiveFeedback += new GiveFeedbackEventHandler(PinBoard_GiveFeedback);
            this.PreviewDragOver  += new DragEventHandler(PinBoard_PreviewDragEnter);
            this.PreviewDragEnter += new DragEventHandler(PinBoard_PreviewDragEnter);

            this.Drop += new DragEventHandler(PinBoard_Drop);

            CollectionView myView = (CollectionView)CollectionViewSource.GetDefaultView(lvw.ItemsSource);

            myView.SortDescriptions.Add(new SortDescription("Tag.LookupType", ListSortDirection.Ascending));
            myView.SortDescriptions.Add(new SortDescription("DisplayLabel", ListSortDirection.Ascending));

            myView.GroupDescriptions.Add(new PinnableLookupTypeGroupDescription());
        }
        public LinkedMultimediaItemsControl(MultimediaLinkViewModel viewModel)
        {
            InitializeComponent();
            this.DataContext = viewModel;

            this.MultimediaID = viewModel.MultimediaID;
            var service = new SupportService(User);

            var mm = service.GetMultimedia(MultimediaID);

            var items = service.ListItemsLinkedToMultimedia(MultimediaID);
            var model = new ObservableCollection <ViewModelBase>();

            foreach (MultimediaLinkedItem item in items)
            {
                if (!string.IsNullOrWhiteSpace(item.CategoryName))
                {
                    LookupType t;
                    if (Enum.TryParse <LookupType>(item.CategoryName, out t))
                    {
                        var vm = PluginManager.Instance.GetViewModel(t, item.IntraCatID);
                        if (vm != null)
                        {
                            model.Add(vm);
                            vm.Tag = t;
                        }
                    }
                }
            }

            lvw.MouseRightButtonUp += new MouseButtonEventHandler(lvw_MouseRightButtonUp);

            ListViewDragHelper.Bind(lvw, (dragged) => {
                if (dragged.Tag is LookupType)
                {
                    var lookupType = (LookupType)dragged.Tag;
                    var plugin     = PluginManager.Instance.GetLookupTypeOwner(lookupType);

                    if (plugin != null)
                    {
                        var data     = new DataObject("Pinnable", dragged);
                        var pinnable = new PinnableObject(plugin.Name, lookupType, dragged.ObjectID.Value);
                        data.SetData(PinnableObject.DRAG_FORMAT_NAME, pinnable);
                        data.SetData(DataFormats.Text, dragged.DisplayLabel);
                        return(data);
                    }
                }
                return(null);
            });

            lvw.ItemsSource = model;
            CollectionView myView = (CollectionView)CollectionViewSource.GetDefaultView(lvw.ItemsSource);

            myView.SortDescriptions.Add(new SortDescription("Tag", ListSortDirection.Ascending));
            myView.SortDescriptions.Add(new SortDescription("DisplayLabel", ListSortDirection.Ascending));

            myView.GroupDescriptions.Add(new LinkedItemGroupDescription());
        }