Example #1
0
        private void CloseCommandExecute(MultiSelectItem obj)
        {
            var index = SelectedItems.IndexOf(obj.Item);

            SelectedItems.Remove(obj.Item);
            if (!(SelectedItems is INotifyCollectionChanged))
            {
                OnSelectedItems_CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, obj.Item, index));
            }
        }
Example #2
0
        private ContentControl GeneratePanelItem(object item)
        {
            MultiSelectItem panelItem = new MultiSelectItem();

            panelItem.Template = selectedItemTemplate;
            panelItem.Content  = GetItemContent(item);
            panelItem.Item     = item;

            return(panelItem);
        }
Example #3
0
        private MultiSelectItem GenerateContainer(int elementIndex, bool isMultiSelectItem)
        {
            MultiSelectItem newElement = new MultiSelectItem();

            var bind = SetElementBinding(elementIndex, isMultiSelectItem);

            newElement.SetBinding(ContentControl.ContentProperty, bind);
            newElement.Item = Items[elementIndex];

            newElement.MouseDown += (sender, e) =>
            {
                var item = ((MultiSelectItem)sender).Item;
                if (((MultiSelectItem)sender).IsSelected)
                {
                    var index = SelectedItems.IndexOf(item);
                    SelectedItems.Remove(item);
                    if (!(SelectedItems is INotifyCollectionChanged))
                    {
                        OnSelectedItems_CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item, index));
                    }
                }
                else
                {
                    SelectedItems.Add(item);
                    if (!(SelectedItems is INotifyCollectionChanged))
                    {
                        OnSelectedItems_CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item));
                    }
                }
            };

            newElement.MouseEnter += (sender, e) =>
            {
                var index = itemContainers.IndexOf(newElement);
                if (index < scroll.VerticalOffset + scroll.ViewportHeight)
                {
                    newElement.Focus();
                }
                else
                {
                    if (scrollFlag == false)
                    {
                        scroll.ScrollToVerticalOffset(scroll.VerticalOffset + 1);
                        newElement.Focus();
                        scrollFlag = true;
                    }
                    else
                    {
                        scrollFlag = false;
                    }
                }
            };

            newElement.KeyDown += (sender, e) =>
            {
                if (e.Key == Key.Enter || e.Key == Key.Space)
                {
                    var item = ((MultiSelectItem)sender).Item;
                    if (((MultiSelectItem)sender).IsSelected)
                    {
                        var index = SelectedItems.IndexOf(item);
                        SelectedItems.Remove(item);
                        if (!(SelectedItems is INotifyCollectionChanged))
                        {
                            OnSelectedItems_CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item, index));
                        }
                    }
                    else
                    {
                        SelectedItems.Add(item);
                        if (!(SelectedItems is INotifyCollectionChanged))
                        {
                            OnSelectedItems_CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item));
                        }
                    }
                }
            };

            return(newElement);
        }