예제 #1
0
 public void OnPlayerChanged(PlayerViewModel changedPlayer)
 {
     OnPropertyChanged(nameof(NumberOfStartingPlayers));
     if (changedPlayer.IsPlaying)
     {
         SelectedItems?.Add(changedPlayer);
     }
     else
     {
         SelectedItems?.Remove(changedPlayer);
     }
     OnPropertyChanged(nameof(SelectedItems));
     OnPropertyChanged(nameof(Players));
     ((AsyncCommand)StartCommand).ChangeCanExecute();
 }
        private void AddSelectedItem(ISelectable item)
        {
            if (item == null)
            {
                return;
            }

            if (SelectedItems?.FirstOrDefault(x => x.Id == item.Id) == null)
            {
                if (item != null && !item.IsSelected)
                {
                    item.IsSelected = true;
                }

                SelectedItems?.Add(item);
            }

            if (ItemsSource is ISelectableCollection collection && collection.SelectedItemsIds?.Contains(item.Id) != true)
            {
                collection.SelectedItemsIds.Add(item.Id);
            }
        }
예제 #3
0
        private void Accept_Click(object sender, RoutedEventArgs e)
        {
            if (Items == null)
            {
                Hide(ContentDialogBaseResult.Cancel);
                return;
            }

            if (IsEditingCompression && SelectedItem is StorageVideo video)
            {
                video.Compression = (int)CompressionValue.Value;

                IsEditingCompression = false;
                return;
            }

            if (IsEditingCropping && SelectedItem is StorageMedia media)
            {
                media.CropRectangle = Cropper.CropRectangle;
                media.Refresh();

                IsEditingCropping = false;
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("SelectedItem"));
                return;
            }

            if (SelectedItem != null && SelectedItems.IsEmpty())
            {
                SelectedItems.Add(SelectedItem);
            }

            if (IsGroupingEnabled)
            {
                SettingsService.Current.IsSendGrouped = IsGrouped;
            }

            Hide(ContentDialogBaseResult.OK);
        }
예제 #4
0
 internal void UpdateSelection(T item, bool selected, bool indeterminate)
 {
     if (SelectedItems == null)
     {
         SelectedItems = new List <T>();
     }
     if (!selected || indeterminate)
     {
         SelectedItems.Remove(item);
         InvokeAsync(async() =>
         {
             try
             {
                 await SelectedItemsChanged.InvokeAsync(SelectedItems);
             }
             catch
             {
             }
         });
     }
     else
     {
         if (!SelectedItems.Contains(item))
         {
             SelectedItems.Add(item);
             InvokeAsync(async() =>
             {
                 try
                 {
                     await SelectedItemsChanged.InvokeAsync(SelectedItems);
                 }
                 catch
                 {
                 }
             });
         }
     }
 }
        /// <summary>
        /// 處理滑鼠左鍵連點在可選/已選項
        /// </summary>
        /// <param name="obj"></param>
        public void AddClickedItem(object obj)
        {
            System.Windows.Controls.TextBlock itemTextBlock = obj as System.Windows.Controls.TextBlock;
            if (itemTextBlock == null)
            {
                return;
            }
            DataTable availableItemsDataTable = Database.DBQueryTool.GetFurnItemInfo(SITE_ID);

            foreach (DataRow row in availableItemsDataTable.Rows.Cast <DataRow>())
            {
                if (row["ITEM_NAME"].ToString() == itemTextBlock.Text)
                {
                    SPCItemInfo info = new SPCItemInfo()
                    {
                        ItemList    = row["FURN_ITEM_INDEX"].ToString(),
                        Flag        = "I",
                        Description = row["ITEM_NAME"].ToString(),
                        Title       = row["ITEM_NAME"].ToString()
                    };
                    if (SelectedItems.Count() > 0)
                    {
                        var a = SelectedItems.Select(x => x.ItemList == info.ItemList);
                        a = a as IEnumerable <bool>;
                        if (!a.Contains(true))
                        {
                            SelectedItems.Add(info);
                            return;
                        }
                    }
                    else
                    {
                        SelectedItems.Add(info);
                        return;
                    }
                }
            }
        }
예제 #6
0
        //we didn't implement a SelectionMode_Changed method since I don't think it would be of any use.


        protected override void ManageSelectedIndex_Changed(DependencyPropertyChangedEventArgs e)
        {
            // Note: in this method, we use "Convert.ToInt32()" intead of casting to "(int)" because otherwise the JS code is not compatible with IE 9 (or Windows Phone 8.0).

            base.ManageSelectedIndex_Changed(e);
            if (e.OldValue != null && e.OldValue is int && Convert.ToInt32(e.OldValue) >= 0 && SelectionMode == SelectionMode.Single)
            {
                INTERNAL_WorkaroundObservableCollectionBugWithJSIL.Clear(SelectedItems);
            }
            if (e.NewValue != null && e.NewValue is int && Convert.ToInt32(e.NewValue) >= 0)
            {
                int newValue = Convert.ToInt32(e.NewValue);
                if (SelectionMode == SelectionMode.Single)
                {
                    INTERNAL_WorkaroundObservableCollectionBugWithJSIL.Clear(SelectedItems);
                    SelectedItems.Add(Items[newValue]);
                }
                else if (!INTERNAL_WorkaroundObservableCollectionBugWithJSIL.Contains(SelectedItems, e.NewValue))
                {
                    SelectedItems.Add(Items[newValue]);
                }
            }
        }
예제 #7
0
        private void TemplateCheck([NotNull] object sender, [NotNull] RoutedEventArgs e)
        {
            Debug.ArgumentNotNull(sender, nameof(sender));
            Debug.ArgumentNotNull(e, nameof(e));

            var checkBox = sender as CheckBox;

            if (checkBox == null)
            {
                return;
            }

            var templateHeader = checkBox.Tag as TemplateHeader;

            if (templateHeader == null)
            {
                return;
            }

            SelectedItems.Add(templateHeader.TemplateId);

            RaiseSelectionChanged();
        }
예제 #8
0
        private void SearchCompanies(List <SearchCompany> itemList, string query)
        {
            foreach (SearchCompany item in itemList)
            {
                AddCompany(item);
            }

            SearchCompany match = Companies.FirstOrDefault(x => x.Name.Equals(query, StringComparison.OrdinalIgnoreCase));

            if (match == null)
            {
                match = Companies.FirstOrDefault(x => x.Name.StartsWith(query, StringComparison.OrdinalIgnoreCase));
            }
            if (match == null)
            {
                match = Companies.FirstOrDefault(x => x.Name.IndexOf(query, StringComparison.OrdinalIgnoreCase) > 0);
            }

            if (match != null)
            {
                SelectedItems.Add(match);
            }
        }
        // Using a DependencyProperty as the backing store for DefaultText.  This enables animation, styling, binding, etc…


        #endregion

        /// <summary>

        ///Whenever a CheckBox is checked, change the text displayed

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        private void CheckBox_Click(object sender, RoutedEventArgs e)
        {
            CheckBox clickedBox = (CheckBox)sender;

            if (SelectedItems == null)
            {
                SelectedItems = new Dictionary <string, object>();
            }

            SelectedItems.Clear();
            foreach (MultiComboBoxModel s in _comboBoxModelList)
            {
                if (s.IsChecked)
                {
                    if (ItemsSource.Count > 0)
                    {
                        SelectedItems.Add(s.EnumValue, ItemsSource[s.EnumValue]);
                    }
                }
            }

            SetText();
        }
예제 #10
0
        protected void CheckBox_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox chbox = (CheckBox)sender;

            if (Marked)
            {
                if (!chbox.Checked)
                {
                    SelectedItems.Add(chbox.ValidationGroup);
                }
                else
                {
                    SelectedItems.Remove(chbox.ValidationGroup);
                }
            }
            else
            {
                if (chbox.Checked)
                {
                    SelectedItems.Add(chbox.ValidationGroup);
                }
                else
                {
                    SelectedItems.Remove(chbox.ValidationGroup);
                }
            }

            QuantitySelectedAndChecked();
            if ((Marked) && (SelectedItems.Count > 0))
            {
                MarkedAll.Attributes["class"] = "";
            }
            else if ((!Marked) && (SelectedItems.Count > 0))
            {
                UnMarkedAll.Attributes["class"] = "";
            }
        }
예제 #11
0
        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);
        }
예제 #12
0
        /// <summary>
        /// Selects items
        /// </summary>
        /// <param name="items"></param>
        protected override void _Select(System.Collections.IEnumerable items)
        {
            // check that editing is not in progress
            if (IsEditingInProgress)
            {
                throw new NotSupportedException((string)App.Current.FindResource("EditingInProcessExceptionMessage"));
            }

            // check that all items are locations
            foreach (object item in items)
            {
                if (!(item is VehicleSpecialty))
                {
                    throw new ArgumentException("VehicleSpecialtiesTypeExceptionMessage");
                }
            }

            // add items to selection
            SelectedItems.Clear();
            foreach (object item in items)
            {
                SelectedItems.Add(item);
            }
        }
예제 #13
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();
 }
예제 #14
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));
         }
     }
 }
예제 #15
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);
         }
     }
 }
예제 #16
0
        /// <summary>
        /// 点击选择复选框时触发此方法
        /// </summary>
        protected Func <CheckboxState, TItem, Task> OnCheck() => async(state, val) =>
        {
            if (state == CheckboxState.Checked)
            {
                SelectedItems.Add(val);
            }
            else
            {
                SelectedItems.Remove(val);
            }

            await OnSelectedRowsChanged();

            if (HeaderCheckbox != null)
            {
                var headerCheckboxState = SelectedItems.Count == 0 && Items.Any()
                    ? CheckboxState.UnChecked
                    : (SelectedItems.Count == Items.Count() ? CheckboxState.Checked : CheckboxState.Mixed);
                await HeaderCheckbox.SetState(headerCheckboxState);
            }

            // https://gitee.com/LongbowEnterprise/BootstrapBlazor/issues/I1UYQG
            StateHasChanged();
        };
예제 #17
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);
                }
            }
        }
예제 #18
0
        protected void OnAttached()
        {
            if (BindableSelectedItems == null)
            {
                BindableSelectedItems = new ObservableCollection <object>();
            }
            else if (BindableSelectedItems is IEnumerable <object> list)
            {
                foreach (var item in list.ToList())
                {
                    SelectedItems.Add(item);
                }
            }

            token = RegisterPropertyChangedCallback(ListViewBase.ItemsSourceProperty, ItemsSourceChanged);

            SelectionChanged -= AssociatedObject_SelectionChanged;
            SelectionChanged += AssociatedObject_SelectionChanged;

            BindableSelectedItems.CollectionChanged -= SelectedItems_CollectionChanged;
            BindableSelectedItems.CollectionChanged += SelectedItems_CollectionChanged;

            UpdateSelection();
        }
예제 #19
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;
     }
 }
예제 #20
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);
         }
     }
 }
        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);
                    }
                }
            }
        }
예제 #22
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();
            }
        }
예제 #23
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);
        }
예제 #24
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);
            }
        }
예제 #25
0
        /// <summary>
        /// Updates the selection for an item based on user interaction.
        /// </summary>
        /// <param name="index">The index of the item.</param>
        /// <param name="select">Whether the item should be selected or unselected.</param>
        /// <param name="rangeModifier">Whether the range modifier is enabled (i.e. shift key).</param>
        /// <param name="toggleModifier">Whether the toggle modifier is enabled (i.e. ctrl key).</param>
        /// <param name="rightButton">Whether the event is a right-click.</param>
        protected void UpdateSelection(
            int index,
            bool select         = true,
            bool rangeModifier  = false,
            bool toggleModifier = false,
            bool rightButton    = false)
        {
            if (index != -1)
            {
                if (select)
                {
                    var mode   = SelectionMode;
                    var multi  = (mode & SelectionMode.Multiple) != 0;
                    var toggle = (toggleModifier || (mode & SelectionMode.Toggle) != 0);
                    var range  = multi && rangeModifier;

                    if (rightButton)
                    {
                        if (!_selection.Contains(index))
                        {
                            UpdateSelectedItem(index);
                        }
                    }
                    else if (range)
                    {
                        UpdateSelectedItems(() =>
                        {
                            var start = SelectedIndex != -1 ? SelectedIndex : 0;
                            var step  = start < index ? 1 : -1;

                            _selection.Clear();

                            for (var i = start; i != index; i += step)
                            {
                                _selection.Add(i);
                            }

                            _selection.Add(index);

                            var first = Math.Min(start, index);
                            var last  = Math.Max(start, index);

                            foreach (var container in ItemContainerGenerator.Containers)
                            {
                                MarkItemSelected(
                                    container.Index,
                                    container.Index >= first && container.Index <= last);
                            }

                            ResetSelectedItems();
                        });
                    }
                    else if (multi && toggle)
                    {
                        UpdateSelectedItems(() =>
                        {
                            if (!_selection.Contains(index))
                            {
                                _selection.Add(index);
                                MarkItemSelected(index, true);
                                SelectedItems.Add(ElementAt(Items, index));
                            }
                            else
                            {
                                _selection.Remove(index);
                                MarkItemSelected(index, false);

                                if (index == _selectedIndex)
                                {
                                    UpdateSelectedItem(_selection.First(), false);
                                }

                                SelectedItems.Remove(ElementAt(Items, index));
                            }
                        });
                    }
                    else if (toggle)
                    {
                        SelectedIndex = (SelectedIndex == index) ? -1 : index;
                    }
                    else
                    {
                        UpdateSelectedItem(index);
                    }

                    if (Presenter?.Panel != null)
                    {
                        var container = ItemContainerGenerator.ContainerFromIndex(index);
                        KeyboardNavigation.SetTabOnceActiveElement(
                            (InputElement)Presenter.Panel,
                            container);
                    }
                }
                else
                {
                    LostSelection();
                }
            }
        }
예제 #26
0
 private void SelectItem(int index)
 {
     SelectedItems.Clear();
     SelectedItems.Add(Items[index]);
 }
예제 #27
0
        /// <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;
            }
        }
        private void MaterialChips_IsSelectedChanged(object sender, EventArgs e)
        {
            if (sender is MaterialChips)
            {
                if (IsMultipleSelection)
                {
                    if (SelectedItems == null)
                    {
                        SelectedItems = new List <string>();
                    }

                    if (((MaterialChips)sender).IsSelected)
                    {
                        SelectedItems.Add(((MaterialChips)sender).Text);
                    }
                    else
                    {
                        SelectedItems.Remove(((MaterialChips)sender).Text);
                    }

                    //bool hasSelected = false;
                    //if (this.flexContainer.Children != null)
                    //{
                    //    foreach (var item in this.flexContainer.Children)
                    //    {
                    //        if (item != null && item is MaterialChips && ((MaterialChips)item).IsSelected)
                    //        {
                    //            hasSelected = true;
                    //            break;
                    //        }
                    //    }
                    //}

                    //if (!hasSelected)
                    //{
                    //    ((MaterialChips)sender).IsSelected = true;
                    //}
                }
                else
                {
                    if (((MaterialChips)sender).IsSelected)
                    {
                        this.SelectedItem = ((MaterialChips)sender).Text;
                    }

                    bool hasSelected = false;
                    if (this.flexContainer.Children != null)
                    {
                        foreach (var item in this.flexContainer.Children)
                        {
                            if (item != null && item is MaterialChips && ((MaterialChips)item).IsSelected)
                            {
                                hasSelected = true;
                                break;
                            }
                        }
                    }

                    if (!hasSelected)
                    {
                        ((MaterialChips)sender).IsSelected = true;
                    }
                }
            }
        }
예제 #29
0
        /// <summary>
        /// Updates the selection for an item based on user interaction.
        /// </summary>
        /// <param name="index">The index of the item.</param>
        /// <param name="select">Whether the item should be selected or unselected.</param>
        /// <param name="rangeModifier">Whether the range modifier is enabled (i.e. shift key).</param>
        /// <param name="toggleModifier">Whether the toggle modifier is enabled (i.e. ctrl key).</param>
        protected void UpdateSelection(
            int index,
            bool select         = true,
            bool rangeModifier  = false,
            bool toggleModifier = false)
        {
            if (index != -1)
            {
                if (select)
                {
                    var mode   = SelectionMode;
                    var toggle = toggleModifier || (mode & SelectionMode.Toggle) != 0;
                    var multi  = (mode & SelectionMode.Multiple) != 0;
                    var range  = multi && SelectedIndex != -1 && rangeModifier;

                    if (!toggle && !range)
                    {
                        SelectedIndex = index;
                    }
                    else if (multi && range)
                    {
                        SynchronizeItems(
                            SelectedItems,
                            GetRange(Items, SelectedIndex, index));
                    }
                    else
                    {
                        var item = ElementAt(Items, index);
                        var i    = SelectedItems.IndexOf(item);

                        if (i != -1 && (!AlwaysSelected || SelectedItems.Count > 1))
                        {
                            SelectedItems.Remove(item);
                        }
                        else
                        {
                            if (multi)
                            {
                                SelectedItems.Add(item);
                            }
                            else
                            {
                                SelectedIndex = index;
                            }
                        }
                    }

                    if (Presenter?.Panel != null)
                    {
                        var container = ItemContainerGenerator.ContainerFromIndex(index);
                        KeyboardNavigation.SetTabOnceActiveElement(
                            (InputElement)Presenter.Panel,
                            container);
                    }
                }
                else
                {
                    LostSelection();
                }
            }
        }
예제 #30
0
 public void AddSelectedItem(Chat chat)
 {
     SelectedItems.Add(chat);
 }