Exemple #1
0
        private void UpdateFilteredSource()
        {
            FilteredSource = Source?.Where(x =>
            {
                // 選択済みのアイテムは選択肢に出さない
                if (SelectedItems?.Contains(x) ?? false)
                {
                    return(false);
                }

                var filterText = editableTextBox?.Text;
                if (string.IsNullOrEmpty(filterText))
                {
                    return(true);
                }

                if (x is string str)
                {
                    return(str.Contains(filterText));
                }

                // リフレクションを用いて、DisplayMemberPathで指定されたプロパティ
                // と比較を行う。DislayMemberPathがないなら、
                // ToStringした結果と比較を行う
                if (!string.IsNullOrWhiteSpace(DisplayMemberPath))
                {
                    displayMemberPropertyInfo = displayMemberPropertyInfo ?? x.GetType().GetProperty(DisplayMemberPath);
                    var value = displayMemberPropertyInfo.GetValue(x);
                    return(value?.ToString().Contains(filterText) ?? false);
                }

                return(x?.ToString().Contains(filterText) ?? false);
            }) ?? Enumerable.Empty <object>();

            if (FilteredSource.Any())
            {
                SetCurrentValue(SelectedItemProperty, !string.IsNullOrWhiteSpace(editableTextBox.Text)
                    ? FilteredSource.FirstOrDefault()
                    : null);
            }
        }
        private Task ToggleRow(SelectedItem item, bool force = false)
        {
            if (!IsDisabled)
            {
                if (SelectedItems.Contains(item))
                {
                    SelectedItems.Remove(item);
                }
                else
                {
                    SelectedItems.Add(item);
                }

                SetValue();

                if (Min > 0 || Max > 0)
                {
                    var validationContext = new ValidationContext(Value !)
                    {
                        MemberName = FieldIdentifier?.FieldName
                    };
                    var validationResults = new List <ValidationResult>();

                    ValidateProperty(SelectedItems.Count, validationContext, validationResults);
                    ToggleMessage(validationResults, true);
                }

                _ = TriggerSelectedItemChanged();

                if (force)
                {
                    StateHasChanged();
                }
            }

            return(Task.CompletedTask);
        }
Exemple #3
0
 private void Selection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     if (!_LockSelectionUpdates)
     {
         _LockSelectionUpdates = true;
         if (e.Action == NotifyCollectionChangedAction.Reset)
         {
             SelectedItems.Clear();
         }
         if (e.OldItems != null)
         {
             if (e.OldItems.Count == SelectedItems.Count)
             {
                 SelectedItems.Clear();
             }
             else
             {
                 foreach (var item in e.OldItems)
                 {
                     SelectedItems.Remove(item);
                 }
             }
         }
         if (e.NewItems != null)
         {
             foreach (var item in e.NewItems)
             {
                 if (!SelectedItems.Contains(item))
                 {
                     SelectedItems.Add(item);
                 }
             }
         }
         _LockSelectionUpdates = false;
     }
 }
Exemple #4
0
 protected void OnInnerStatusChanged(Status status, TModel model)
 {
     if (SelectedItems == null)
     {
         return;
     }
     if (status == Status.Checked)
     {
         lock (SelectedItems)
         {
             if (!SelectedItems.Contains(model))
             {
                 SelectedItems.Add(model);
             }
         }
     }
     else if (status == Status.UnChecked)
     {
         lock (SelectedItems)
         {
             SelectedItems.Remove(model);
         }
     }
 }
Exemple #5
0
 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
 {
     if (e.Row.RowIndex > -1 && this.SelectedItems != null)
     {
         CheckBox cbx = (CheckBox)e.Row.FindControl("cbItem");
         int      i   = e.Row.RowIndex;
         string   id  = string.Format("{0}${1}${2}${3}${4}${5}",
                                      this.GridView1.DataKeys[i].Values[0].ToString(),
                                      this.GridView1.DataKeys[i].Values[1].ToString(),
                                      this.GridView1.DataKeys[i].Values[2].ToString(),
                                      this.GridView1.DataKeys[i].Values[3].ToString(),
                                      this.GridView1.DataKeys[i].Values[4].ToString(),
                                      this.GridView1.DataKeys[i].Values[5].ToString()
                                      );
         if (SelectedItems.Contains(id))
         {
             cbx.Checked = true;
         }
         else
         {
             cbx.Checked = false;
         }
     }
 }
Exemple #6
0
 public void SelectItem(ExTreeViewItem item)
 {
     FocusItem(item);
     if (!CtrlPressed)
     {
         SelectedItems.Clear();
     }
     if (ShiftPressed)
     {
         if (shiftEnd != null)                //Erase previous selection of shift
         {
             foreach (var forEachItem in GetItemsBetween(shiftStart, shiftEnd))
             {
                 SelectedItems.Remove(forEachItem.DataContext);
             }
         }
         shiftEnd = item;
         foreach (var forEachItem in GetItemsBetween(shiftStart, shiftEnd))
         {
             SelectedItems.Add(forEachItem.DataContext);
         }
     }
     else
     {
         shiftEnd   = null;
         shiftStart = item;
         if (CtrlPressed && SelectedItems.Contains(item.DataContext))
         {
             SelectedItems.Remove(item.DataContext);
         }
         else
         {
             SelectedItems.Add(item.DataContext);
         }
     }
 }
Exemple #7
0
 private void NewSelection(T selectedItem)
 {
     if (multiModifierDown)
     {
         if (SelectedItems.Add(selectedItem))
         {
             Selection?.Invoke(this, new ItemSelectionEventArgs <T>(selectedItem, SelectionType.Selected));
         }
     }
     else
     {
         bool alreadySelected = SelectedItems.Contains(selectedItem);
         var  toRemove        = SelectedItems.Except(selectedItem).ToArray();
         foreach (var b in toRemove)
         {
             Deselect(b);
         }
         if (!alreadySelected)
         {
             SelectedItems.Add(selectedItem);
             Selection?.Invoke(this, new ItemSelectionEventArgs <T>(selectedItem, SelectionType.Selected));
         }
     }
 }
Exemple #8
0
        /// <summary>
        /// Utillity method setting the selected value of the current treeViewItem and
        /// adding and remove it from the selected items collection respectively.
        /// </summary>
        /// <param name="item">
        /// The item whoes IsSelected property value defines what is about to happen
        /// to the the current item.
        /// </param>
        /// <param name="itemState">
        /// The value to set to the IsSelected property of the current treeviewitem.
        /// </param>
        private void SelectItem(TreeViewItem item, bool itemState)
        {
            if (item == null)
            {
                return;
            }

            if (SelectedItems != null)
            {
                if (itemState == true)
                {
                    item.IsSelected = itemState;
                    if (!SelectedItems.Contains(item))
                    {
                        SelectedItems.Add(item);
                    }
                }
                else
                {
                    item.IsSelected = itemState;
                    SelectedItems.Remove(item);
                }
            }
        }
        public void SelectItems(Func <object, bool> predicate)
        {
            if (SelectionMode == SelectionMode.Single)
            {
                throw new InvalidOperationException("SelectionMode must not be Single");
            }

            foreach (var item in Items)
            {
                var selected = predicate(item);

                if (selected != SelectedItems.Contains(item))
                {
                    if (selected)
                    {
                        SelectedItems.Add(item);
                    }
                    else
                    {
                        SelectedItems.Remove(item);
                    }
                }
            }
        }
Exemple #10
0
 private void UpdateFromSelectedMemberPathValues()
 {
     _ignoreSelectedItemsCollectionChanged++;
     foreach (object item in ItemsCollection)
     {
         bool?selectedMemberPathValue = GetSelectedMemberPathValue(item);
         if (selectedMemberPathValue.HasValue)
         {
             if (selectedMemberPathValue.Value)
             {
                 if (!SelectedItems.Contains(item))
                 {
                     SelectedItems.Add(item);
                 }
             }
             else if (SelectedItems.Contains(item))
             {
                 SelectedItems.Remove(item);
             }
         }
     }
     _ignoreSelectedItemsCollectionChanged--;
     UpdateFromSelectedItems();
 }
        /// <summary>
        /// Called when the <see cref="SelectedItems"/> CollectionChanged event is raised.
        /// </summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event args.</param>
        private void SelectedItemsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (_syncingSelectedItems)
            {
                return;
            }

            void Add(IList newItems, IList addedItems = null)
            {
                foreach (var item in newItems)
                {
                    var index = MarkItemSelected(item, true);

                    if (index != -1 && _selection.Add(index) && addedItems != null)
                    {
                        addedItems.Add(item);
                    }
                }
            }

            void UpdateSelection()
            {
                if ((SelectedIndex != -1 && !_selection.Contains(SelectedIndex)) ||
                    (SelectedIndex == -1 && _selection.HasItems))
                {
                    _selectedIndex = _selection.First();
                    _selectedItem  = ElementAt(Items, _selectedIndex);
                    RaisePropertyChanged(SelectedIndexProperty, -1, _selectedIndex, BindingPriority.LocalValue);
                    RaisePropertyChanged(SelectedItemProperty, null, _selectedItem, BindingPriority.LocalValue);
                }
            }

            IList added   = null;
            IList removed = null;

            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
            {
                Add(e.NewItems);
                UpdateSelection();
                added = e.NewItems;
            }

            break;

            case NotifyCollectionChangedAction.Remove:
                if (SelectedItems.Count == 0)
                {
                    SelectedIndex = -1;
                }

                foreach (var item in e.OldItems)
                {
                    var index = MarkItemSelected(item, false);
                    _selection.Remove(index);
                }

                removed = e.OldItems;
                break;

            case NotifyCollectionChangedAction.Replace:
                throw new NotSupportedException("Replacing items in a SelectedItems collection is not supported.");

            case NotifyCollectionChangedAction.Move:
                throw new NotSupportedException("Moving items in a SelectedItems collection is not supported.");

            case NotifyCollectionChangedAction.Reset:
            {
                removed = new List <object>();
                added   = new List <object>();

                foreach (var index in _selection.ToList())
                {
                    var item = ElementAt(Items, index);

                    if (!SelectedItems.Contains(item))
                    {
                        MarkItemSelected(index, false);
                        removed.Add(item);
                        _selection.Remove(index);
                    }
                }

                Add(SelectedItems, added);
                UpdateSelection();
            }

            break;
            }

            if (added?.Count > 0 || removed?.Count > 0)
            {
                var changed = new SelectionChangedEventArgs(
                    SelectionChangedEvent,
                    added ?? Empty,
                    removed ?? Empty);
                RaiseEvent(changed);
            }
        }
Exemple #12
0
        private void LoadTemplates([NotNull] IEnumerable <TemplateHeader> templates)
        {
            Debug.ArgumentNotNull(templates, nameof(templates));

            Templates = templates.Select(t => new CheckedTemplateHeader(t.TemplateUri, t.Name, t.Icon, t.Path, t.Section, t.IsBranch, SelectedItems.Contains(t.TemplateUri.ItemId))).ToList();

            TemplateListView.ItemsSource = Templates;

            listViewSorter.Resort();
            view = CollectionViewSource.GetDefaultView(Templates) as CollectionView;
            if (view == null)
            {
                return;
            }

            var groupDescription = new PropertyGroupDescription("Section")
            {
                StringComparison = StringComparison.InvariantCultureIgnoreCase
            };

            var collection = view.GroupDescriptions;

            if (collection != null)
            {
                collection.Clear();
                collection.Add(groupDescription);
            }

            view.Filter = delegate(object o)
            {
                var templateHeader = o as TemplateHeader;
                return(templateHeader != null && templateHeader.Name.IsFilterMatch(TemplateSelectorFilter.Text));
            };

            view.Refresh();

            TemplateListView.ResizeColumn(NameColumn);

            Loading.Visibility          = Visibility.Collapsed;
            TemplateListView.Visibility = Visibility.Visible;

            var loaded = TemplatesLoaded;

            if (loaded != null)
            {
                loaded(this, EventArgs.Empty);
            }
        }
        private void DrawData(PaintEventArgs e, List <RollColumn> visibleColumns)
        {
            if (QueryItemText != null)
            {
                if (HorizontalOrientation)
                {
                    int startRow = FirstVisibleRow;
                    int range    = Math.Min(LastVisibleRow, RowCount - 1) - startRow + 1;

                    Gdi.PrepDrawString(NormalFont, _foreColor);
                    for (int i = 0, f = 0; f < range; i++, f++)
                    {
                        f += lagFrames[i];
                        int LastVisible = LastVisibleColumnIndex;
                        for (int j = FirstVisibleColumn; j <= LastVisible; j++)
                        {
                            Bitmap image         = null;
                            int    x             = 0;
                            int    y             = 0;
                            int    bitmapOffsetX = 0;
                            int    bitmapOffsetY = 0;

                            if (QueryItemIcon != null)
                            {
                                QueryItemIcon(f + startRow, visibleColumns[j], ref image, ref bitmapOffsetX, ref bitmapOffsetY);
                            }

                            if (image != null)
                            {
                                x = RowsToPixels(i) + CellWidthPadding + bitmapOffsetX;
                                y = (j * CellHeight) + (CellHeightPadding * 2) + bitmapOffsetY;
                                Gdi.DrawBitmap(image, new Point(x, y), true);
                            }

                            string text;
                            int    strOffsetX = 0;
                            int    strOffsetY = 0;
                            QueryItemText(f + startRow, visibleColumns[j], out text, ref strOffsetX, ref strOffsetY);

                            // Center Text
                            x = RowsToPixels(i) + (CellWidth - text.Length * _charSize.Width) / 2;
                            y = (j * CellHeight) + CellHeightPadding - VBar.Value;
                            var point = new Point(x + strOffsetX, y + strOffsetY);

                            var rePrep = false;
                            if (j == 1)
                            {
                                if (SelectedItems.Contains(new Cell {
                                    Column = visibleColumns[j], RowIndex = i + startRow
                                }))
                                {
                                    Gdi.PrepDrawString(RotatedFont, SystemColors.HighlightText);
                                    rePrep = true;
                                }
                                else if (j == 1)
                                {
                                    //1. not sure about this; 2. repreps may be excess, but if we render one column at a time, we do need to change back after rendering the header
                                    rePrep = true;
                                    Gdi.PrepDrawString(RotatedFont, _foreColor);
                                }
                            }



                            if (!string.IsNullOrWhiteSpace(text))
                            {
                                Gdi.DrawString(text, point);
                            }

                            if (rePrep)
                            {
                                Gdi.PrepDrawString(NormalFont, _foreColor);
                            }
                        }
                    }
                }
                else
                {
                    int startRow = FirstVisibleRow;
                    int range    = Math.Min(LastVisibleRow, RowCount - 1) - startRow + 1;

                    Gdi.PrepDrawString(NormalFont, _foreColor);
                    int xPadding = CellWidthPadding + 1 - HBar.Value;
                    for (int i = 0, f = 0; f < range; i++, f++)                     // Vertical
                    {
                        f += lagFrames[i];
                        int LastVisible = LastVisibleColumnIndex;
                        for (int j = FirstVisibleColumn; j <= LastVisible; j++)                         // Horizontal
                        {
                            RollColumn col = visibleColumns[j];

                            string text;
                            int    strOffsetX = 0;
                            int    strOffsetY = 0;
                            Point  point      = new Point(col.Left.Value + xPadding, RowsToPixels(i) + CellHeightPadding);

                            Bitmap image         = null;
                            int    bitmapOffsetX = 0;
                            int    bitmapOffsetY = 0;

                            if (QueryItemIcon != null)
                            {
                                QueryItemIcon(f + startRow, visibleColumns[j], ref image, ref bitmapOffsetX, ref bitmapOffsetY);
                            }

                            if (image != null)
                            {
                                Gdi.DrawBitmap(image, new Point(point.X + bitmapOffsetX, point.Y + bitmapOffsetY + CellHeightPadding), true);
                            }

                            QueryItemText(f + startRow, visibleColumns[j], out text, ref strOffsetX, ref strOffsetY);

                            bool rePrep = false;
                            if (SelectedItems.Contains(new Cell {
                                Column = visibleColumns[j], RowIndex = f + startRow
                            }))
                            {
                                Gdi.PrepDrawString(NormalFont, SystemColors.HighlightText);
                                rePrep = true;
                            }

                            if (!string.IsNullOrWhiteSpace(text))
                            {
                                Gdi.DrawString(text, new Point(point.X + strOffsetX, point.Y + strOffsetY));
                            }

                            if (rePrep)
                            {
                                Gdi.PrepDrawString(NormalFont, _foreColor);
                            }
                        }
                    }
                }
            }
        }
 private bool GetCheckedState(SelectedItem item) => SelectedItems.Contains(item);
        public void RenderGrid()
        {
            var stream = new ColloredStringBuilder();

            SourceList.CollectionChanged -= SourceListOnCollectionChanged;

            //For Native type Support we need to wrap the Type into a Anonymos one



            if (ObserveList)
            {
                SourceList.CollectionChanged += SourceListOnCollectionChanged;
            }

            var size   = 0;
            var fod    = SourceList.FirstOrDefault();
            var length = SourceList.Count;

            if (fod == null)
            {
                return;
            }

            Target = fod.GetType();
            if (Target.IsPrimitive)
            {
                SourceList = new ObservableCollection <object>(SourceList.Select(s => new { s }));
                Target     = fod.GetType();
            }

            var props =
                Target.GetProperties().Select(s =>
            {
                var name = s.Name;
                if (RenderTypeName)
                {
                    name = string.Format("{0} {{{1}}}", name, s.PropertyType.ToString());
                }

                var valueInformations = new ValueInformations()
                {
                    GetValue       = s.GetValue,
                    MaxContentSize = SourceList.Max(e =>
                    {
                        var value = s.GetValue(e);
                        if (value != null)
                        {
                            return(value.ToString().Length);
                        }
                        return(Null.ToString().Length);
                    }),
                    Name = name,
                };

                return(valueInformations);
            }).ToList();


            if (RenderRowNumber)
            {
                int fakeId = 0;
                //fake new Column
                props.Insert(0, new ValueInformations()
                {
                    Name           = "Nr",
                    MaxContentSize = length.ToString().Length,
                    GetValue       = o => fakeId++
                });
            }

            foreach (var valueInfo in props)
            {
                valueInfo.Name = AlignValueToSize(valueInfo.Name, valueInfo.MaxSize);
                size          += valueInfo.Name.Length;
            }

            var headerInfos = props.Select(s => s.Name).ToList();

            this.ConsolePropertyGridStyle.RenderHeader(stream, headerInfos);

            stream.AppendLine();

            if (Console.WindowWidth < size)
            {
                Console.WindowWidth = size + 30;
            }

            for (int i = 0; i < length; i++)
            {
                var item = SourceList[i];

                var selected = SelectedItems != null && SelectedItems.Contains(item);
                var focused  = FocusedItem == item;

                this.ConsolePropertyGridStyle.BeginRenderProperty(stream, i, length.ToString().Length, selected, focused);

                for (int index = 0; index < props.Count; index++)
                {
                    var propertyInfo = props[index];
                    var value        = propertyInfo.GetValue(item) ?? Null;
                    var norm         = AlignValueToSize(value.ToString(), propertyInfo.MaxSize);
                    this.ConsolePropertyGridStyle.RenderNextProperty(stream, norm, index, selected, focused);
                }
                this.ConsolePropertyGridStyle.EndRenderProperty(stream, i, selected, focused);
                stream.AppendLine();
            }


            this.ConsolePropertyGridStyle.RenderFooter(stream, headerInfos);
            stream.AppendLine();

            if (RenderSum)
            {
                this.ConsolePropertyGridStyle.RenderSummary(stream, length);
                stream.AppendLine();
            }

            if (_extraInfos.Length > 0)
            {
                this.ConsolePropertyGridStyle.RenderAdditionalInfos(stream, _extraInfos);
                stream.AppendLine();
            }

            if (!PersistendAdditionalInfos)
            {
                _extraInfos.Clear();
            }

            if (ClearConsole)
            {
                Console.Clear();
            }
            stream.Render();
        }
Exemple #16
0
        /// <summary>
        /// Panel click. Handles item selection.
        /// </summary>
        private void OnPanelClick(object sender, MouseEventArgs e)
        {
            // Is touch enabled?
            if (M.TouchEnabled)
            {
                // Cancels click event if click wasn't accurate enough
                // Ensures better scrolling experience
                if (mouseDownPoint != e.Location)
                {
                    return;
                }
            }

            // Get focus
            Focus();

            // Do we have more than one item?
            if (Items.Count > 0)
            {
                // Iterate over all displayed items
                foreach (MItem item in DisplayedItems)
                {
                    // Did user clicked on currently iterated item?
                    if (item.Bounds.Contains(mouseLocation))
                    {
                        // Modify mouse event arguments
                        MouseEventArgs clickArgs = new MouseEventArgs(
                            e.Button,
                            e.Clicks,
                            e.X,
                            Math.Abs(Panel.AutoScrollPosition.Y) + e.Y,
                            e.Delta
                            );

                        // Trigger clicked item click event
                        item.TriggerMouseClick(this, clickArgs);

                        // Did user left-clicked?
                        if (e.Button == MouseButtons.Left)
                        {
                            // Ignore if item is divider
                            if (item.Divider)
                            {
                                continue;
                            }

                            // Change selected item
                            if (MultiSelect)
                            {
                                // Is CTRL key pressed?
                                if ((ModifierKeys & Keys.Control) == Keys.Control)
                                {
                                    // Check if item was not selected before
                                    if (!SelectedItems.Contains(item))
                                    {
                                        // Add item to SelectedItems collection
                                        SelectedItems.Add(item);
                                    }
                                }
                                else
                                {
                                    // Clear items
                                    SelectedItems.Clear();

                                    // Add item to SelectedItems collection
                                    SelectedItems.Add(item);
                                }
                            }
                            else
                            {
                                // Update selected item
                                SelectedItem = item;
                            }

                            // Trigger selected item changed event
                            SelectedItemChanged?.Invoke(this, new PropertyChangedEventArgs("SelectedItemChanged"));
                        }
                    }
                }
            }

            // Redraw
            Invalidate(true);
        }
Exemple #17
0
        void HandleOwnerSelectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            // When 'Updating' is false it means the user has directly modified the collection
            // by calling ListBox.SelectedItems.[Add|Remove]. In this case we need to ensure we
            // don't have a duplicate selection.
            if (!Updating)
            {
                if (Mode == SelectionMode.Single)
                {
                    throw new InvalidOperationException("SelectedItems cannot be modified directly when in Single select mode");
                }
                try {
                    Updating = true;
                    switch (e.Action)
                    {
                    case NotifyCollectionChangedAction.Add:
                        if (!SelectedItems.Contains(e.NewItems [0]))
                        {
                            AddToSelected(e.NewItems [0]);
                        }
                        break;

                    case NotifyCollectionChangedAction.Remove:
                        if (SelectedItems.Contains(e.OldItems [0]))
                        {
                            RemoveFromSelected(e.OldItems [0]);
                        }
                        break;

                    case NotifyCollectionChangedAction.Replace:
                        if (SelectedItems.Contains(e.OldItems [0]))
                        {
                            RemoveFromSelected(e.OldItems [0]);
                        }
                        if (!SelectedItems.Contains(e.NewItems [0]))
                        {
                            AddToSelected(e.NewItems [0]);
                        }
                        break;

                    case NotifyCollectionChangedAction.Reset:
                        foreach (var v in SelectedItems.Where(o => !Owner.SelectedItems.Contains(o)).ToArray())
                        {
                            if (SelectedItems.Contains(v))
                            {
                                RemoveFromSelected(v);
                            }
                        }
                        foreach (var v in Owner.SelectedItems.Where(o => !SelectedItems.Contains(o)).ToArray())
                        {
                            if (!SelectedItems.Contains(v))
                            {
                                AddToSelected(v);
                            }
                        }
                        break;
                    }

                    Owner.SelectedItemsIsInvalid = true;
                } finally {
                    Updating = false;
                }
            }
        }
Exemple #18
0
        public void Select(object item, bool ignoreSelectedValue)
        {
            // Ignore any Select requests for items which aren't in the  owners Items list
            if (!Owner.Items.Contains(item))
            {
                return;
            }

            bool selected = SelectedItems.Contains(item);

            try {
                Updating = true;

                switch (Mode)
                {
                case SelectionMode.Single:
                    // When in single select mode we unselect the item if the Control key is held,
                    // otherwise we just ensure that the SelectedIndex is in sync. It could be out
                    // of sync if the user inserts an item before the current selected item.
                    if (selected)
                    {
                        if (ModifierKeys.Control == (Keyboard.Modifiers & ModifierKeys.Control))
                        {
                            ClearSelection(ignoreSelectedValue);
                        }
                        else
                        {
                            UpdateSelectorProperties(SelectedItem, Owner.Items.IndexOf(SelectedItem), Owner.SelectedValue);
                        }
                    }
                    else
                    {
                        ReplaceSelection(item);
                    }
                    break;

                case SelectionMode.Extended:
                    if ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift)
                    {
                        int selectedIndex = Owner.Items.IndexOf(SelectedItem);
                        if (SelectedItems.Count == 0)
                        {
                            SelectRange(0, Owner.Items.IndexOf(item));
                        }
                        else
                        {
                            SelectRange(selectedIndex, Owner.Items.IndexOf(item));
                        }
                    }
                    else if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
                    {
                        if (!selected)
                        {
                            AddToSelected(item);
                        }
                    }
                    else
                    {
                        if (selected)
                        {
                            RemoveFromSelected(item);
                        }
                        else
                        {
                            AddToSelected(item);
                        }
                    }
                    break;

                case SelectionMode.Multiple:
                    if (SelectedItems.Contains(item))
                    {
                        UpdateSelectorProperties(SelectedItem, Owner.Items.IndexOf(SelectedItem), Owner.SelectedValue);
                    }
                    else
                    {
                        AddToSelected(item);
                    }
                    break;

                default:
                    throw new NotSupportedException(string.Format("SelectionMode {0} is not support", Mode));
                }
            } finally {
                Updating = false;
            }
        }
Exemple #19
0
        protected override void OnItemsChanged(NotifyCollectionChangedEventArgs e)
        {
            if (Initializing)
            {
                base.OnItemsChanged(e);
                return;
            }

            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                ListBoxItem item = e.NewItems [0] as ListBoxItem;
                if (item != null && item.IsSelected && !SelectedItems.Contains(item))
                {
                    Selection.Select(item);
                }
                else if (SelectedItem != null)
                {
                    // The index of our selected item may have changed, so we need to
                    // reselect it to refresh the SelectedIndex property. This won't raise
                    // a SelectionChanged event as the actual object is the same.
                    Selection.Select(SelectedItem);
                }
                break;

            case NotifyCollectionChangedAction.Reset:
                object o;
                if (ItemsSource is ICollectionView && SynchronizeWithCurrentItem)
                {
                    o = ((ICollectionView)ItemsSource).CurrentItem;
                }
                else
                {
                    o = SelectedItem;
                }
                if (Items.Contains(o))
                {
                    Selection.Select(o);
                }
                else
                {
                    Selection.ClearSelection();
                }
                break;

            case NotifyCollectionChangedAction.Remove:
                if (SelectedItems.Contains(e.OldItems [0]))
                {
                    Selection.Unselect(e.OldItems [0]);
                }
                else if (e.OldStartingIndex <= SelectedIndex)
                {
                    Selection.Select(SelectedItem);
                }
                break;

            case NotifyCollectionChangedAction.Replace:
                Selection.Unselect(e.OldItems [0]);
                break;

            default:
                throw new NotSupportedException(string.Format("Collection changed action '{0}' not supported", e.Action));
            }
            base.OnItemsChanged(e);
        }
Exemple #20
0
 private bool ConvertSelected(StorageMedia media)
 {
     return(SelectedItems.Contains(media));
 }
Exemple #21
0
        internal override void OnSelectedItemChanged(object oldSelectedItem, object selectedItem, bool updateItemSelectedState)
        {
            if (_modifyingSelectionInternally)
            {
                return;
            }
            if (IsSelectionMultiple)
            {
                var items = GetItems();
                if (selectedItem == null || items.Contains(selectedItem))
                {
                    object[] removedItems = null;
                    object[] addedItems   = null;
                    try
                    {
                        _modifyingSelectionInternally = true;
                        removedItems = SelectedItems.Except(selectedItem).ToObjectArray();
                        var isRealSelection = selectedItem != null || items.Contains(null);
                        addedItems = SelectedItems.Contains(selectedItem) || !isRealSelection ? new object[0] : new[] { selectedItem };
                        SelectedItems.Clear();
                        if (isRealSelection)
                        {
                            SelectedItems.Add(selectedItem);
                        }
                    }
                    finally
                    {
                        _modifyingSelectionInternally = false;
                    }
                    //Invoke event after resetting flag, in case callbacks in user code modify the collection
                    if (addedItems.Length > 0 || removedItems.Length > 0)
                    {
                        InvokeSelectionChanged(removedItems, addedItems);
                    }
                }
                else
                {
                    SelectedItem = oldSelectedItem;
                }
            }
            else
            {
                try
                {
                    _modifyingSelectionInternally = true;

                    if (selectedItem != null)
                    {
                        SelectedItems.Update(new[] { selectedItem });
                    }
                    else
                    {
                        SelectedItems.Clear();
                    }
                }
                finally
                {
                    _modifyingSelectionInternally = false;
                }

                base.OnSelectedItemChanged(
                    oldSelectedItem: oldSelectedItem,
                    selectedItem: selectedItem,
                    updateItemSelectedState: true);
            }
        }
 /// <summary>
 /// 获得 当前行是否被选中
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 protected CheckboxState RowCheckState(TItem item) => SelectedItems.Contains(item) ? CheckboxState.Checked : CheckboxState.UnChecked;
        private void Handle(long chatId, long order)
        {
            if (_deletedChats.ContainsKey(chatId))
            {
                if (order == 0)
                {
                    _deletedChats.Remove(chatId);
                }
                else
                {
                    return;
                }
            }

            var items = Items;

            var chat = GetChat(chatId);

            if (chat != null && _chatList.ListEquals(chat.ChatList))
            {
                if (items.Filter != null && !items.Filter.Intersects(chat))
                {
                    BeginOnUIThread(() => items.Remove(chat));
                    return;
                }

                BeginOnUIThread(async() =>
                {
                    if (order > items.LastOrder || (order == items.LastOrder && chatId >= items.LastChatId))
                    {
                        var index = items.IndexOf(chat);
                        var next  = items.NextIndexOf(chat);

                        if (next >= 0 && index != next)
                        {
                            items.Remove(chat);
                            items.Insert(next, chat);

                            if (chat.Id == _selectedItem)
                            {
                                Delegate?.SetSelectedItem(chat);
                            }
                            if (SelectedItems.Contains(chat))
                            {
                                Delegate?.SetSelectedItems(_selectedItems);
                            }
                        }
                    }
                    else
                    {
                        items.Remove(chat);

                        if (chat.Id == _selectedItem)
                        {
                            Delegate?.SetSelectedItem(chat);
                        }
                        if (SelectedItems.Contains(chat))
                        {
                            SelectedItems.Remove(chat);
                            Delegate?.SetSelectedItems(_selectedItems);
                        }

                        if (!items.HasMoreItems)
                        {
                            await items.LoadMoreItemsAsync(0);
                        }
                    }
                });
            }
        }
        internal void OnPointerMoved(LazoListViewItem item, PointerRoutedEventArgs e)
        {
            var child = ItemFromContainer(item);

            if (child == null)
            {
                return;
            }

            if ((_firstItem != null && _firstItem != child) || !_pressed || !e.Pointer.IsInContact || e.Pointer.PointerDeviceType != PointerDeviceType.Mouse)
            {
                return;
            }

            var point = e.GetCurrentPoint(item);

            if (!point.Properties.IsLeftButtonPressed)
            {
                return;
            }

            e.Handled = true;

            if (_firstItem == null)
            {
                _firstItem = ItemFromContainer(item);
                _ranges    = SelectedRanges.ToArray();
                _operation = !item.IsSelected;

                _position = point.Position;
            }
            else if (_firstItem == child)
            {
                var contains = SelectedItems.Contains(child);

                var delta = Math.Abs(point.Position.Y - _position.Y);
                if (delta > 10)
                {
                    SelectionMode = ListViewSelectionMode.Multiple;

                    if (_operation && !contains)
                    {
                        SelectedItems.Add(child);
                    }
                    else if (!_operation && contains)
                    {
                        SelectedItems.Remove(child);
                    }
                }
                else
                {
                    if (_operation && contains)
                    {
                        SelectedItems.Remove(child);
                    }
                    else if (!_operation && !contains)
                    {
                        SelectedItems.Add(child);
                    }
                }
            }
        }
Exemple #25
0
        /// <summary>
        /// Draw the window.
        /// </summary>
        protected virtual void OnGUI()
        {
            InitializeStyles();
            if (!String.IsNullOrEmpty(Caption))
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.SelectableLabel(Caption);
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.Space();
            }
            EditorGUILayout.BeginVertical();
            scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
            int displayIndex = 0;

            foreach (var indexAndItem in sortedItems)
            {
                var  item     = indexAndItem.Value.Key;
                var  display  = indexAndItem.Value.Value;
                bool selected = SelectedItems.Contains(item);
                EditorGUILayout.BeginHorizontal(
                    selected ? selectedItemStyles[displayIndex % selectedItemStyles.Length] :
                    unselectedItemStyles[displayIndex % unselectedItemStyles.Length]);
                bool currentlySelected = EditorGUILayout.ToggleLeft(display, selected);
                if (currentlySelected != selected)
                {
                    if (currentlySelected)
                    {
                        SelectedItems.Add(item);
                    }
                    else
                    {
                        SelectedItems.Remove(item);
                    }
                }
                EditorGUILayout.EndHorizontal();
                displayIndex++;
            }
            EditorGUILayout.EndScrollView();
            EditorGUILayout.EndVertical();
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("All"))
            {
                SelectAll();
            }
            if (GUILayout.Button("None"))
            {
                SelectNone();
            }
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            bool cancel = GUILayout.Button(CancelLabel);
            bool apply  = GUILayout.Button(ApplyLabel);

            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();
            if (cancel || apply)
            {
                if (cancel && OnCancel != null)
                {
                    OnCancel();
                }
                if (apply && OnApply != null)
                {
                    OnApply();
                }
                Close();
            }
        }
Exemple #26
0
 /// <summary>
 /// Checks if an item is selected.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <returns>True if selected; Otherwise, false.</returns>
 public virtual bool IsSelected(object item)
 {
     return(SelectedItems.Contains(item));
 }
        /// <summary>
        /// Provides different key shortcuts
        /// </summary>
        /// <param name="key"></param>
        public void KeyDown(VirtualKey key)
        {
            switch (key)
            {
            case VirtualKey.Left:
                NavigateBack.ExecuteWhen();
                break;

            case VirtualKey.Right:
                NavigateForward.ExecuteWhen();
                break;

            case VirtualKey.Back:
                NavigateBack.ExecuteWhen();
                break;

            case VirtualKey.F5:
                Refresh();
                break;

            case VirtualKey.F2:
                RenameStorageItemSelectedAsync();
                break;

            case VirtualKey.Delete:
                DeleteStorageItemSelected();
                break;
            }


            var ctrlDown = Window.Current.CoreWindow.GetKeyState(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down);

            if (!ctrlDown)
            {
                return;
            }

            switch (key)
            {
            case VirtualKey.R:
                Refresh();
                break;

            case VirtualKey.C:
                CopyStorageItemSelected();
                break;

            case VirtualKey.X:
                CutStorageItemSelected();
                break;

            case VirtualKey.V:
                PasteStorageItemSelected();
                break;

            case VirtualKey.A:
                if (SelectedItems.Count == FileSystemElements.Count)
                {
                    SelectedItems.Clear();
                }
                else
                {
                    for (int i = 0; i < FileSystemElements.Count; i++)
                    {
                        if (!SelectedItems.Contains(FileSystemElements[i]))
                        {
                            SelectedItems.Add(FileSystemElements[i]);
                        }
                    }
                }

                break;
            }
        }
Exemple #28
0
 public bool IsItemSelected(Chat chat)
 {
     return(SelectedItems.Contains(chat));
 }
 /// <summary>
 /// 检查当前行是否被选中方法
 /// </summary>
 /// <param name="val"></param>
 /// <returns></returns>
 protected virtual bool CheckActive(TItem val) => SelectedItems.Contains(val);
Exemple #30
0
        /// <summary>
        /// Called when a page becomes the active page in a frame.
        /// </summary>
        /// <param name="e">An object that contains the event data.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (null == e)
            {
                throw new ArgumentNullException("e");
            }

            base.OnNavigatedTo(e);

            // Restore Value if returning to application (to avoid inconsistent state)
            if (State.ContainsKey(StateKey_Value))
            {
                State.Remove(StateKey_Value);

                // Back out from picker page for consistency with behavior of core pickers in this scenario
                if (NavigationService.CanGoBack)
                {
                    NavigationService.GoBack();
                    return;
                }
            }

            // Automatically uppercase the text for the header.
            if (null != HeaderText)
            {
                HeaderTitle.Text = HeaderText.ToUpper(CultureInfo.CurrentCulture);
            }

            Picker.DataContext = Items;

            Picker.SelectionMode = SelectionMode;

            if (null != FullModeItemTemplate)
            {
                Picker.ItemTemplate = FullModeItemTemplate;
            }
            if (null != FullModeItemsPanel)
            {
                Picker.ItemsPanel = FullModeItemsPanel;
            }

            if (SelectionMode == SelectionMode.Single)
            {
                ApplicationBar.IsVisible = false;

                Picker.SelectedItem = SelectedItem;
            }
            else
            {
                ApplicationBar.IsVisible  = true;
                Picker.ItemContainerStyle = (Style)Resources["ListBoxItemCheckedStyle"];

                foreach (object item in Items)
                {
                    if (null != SelectedItems && SelectedItems.Contains(item))
                    {
                        Picker.SelectedItems.Add(item);
                    }
                }
            }
        }