Inheritance: ItemsControl
        protected override void AttachBehaviors(IRegion region, Selector regionTarget)
        {
            base.AttachBehaviors(region, regionTarget);

            OutlookBarPublishBehavior behavior = new OutlookBarPublishBehavior(regionTarget, eventAggregator);
            behavior.Attach();
        }
Esempio n. 2
0
        public static void SetCommand(Selector selector, ICommand command)
        {
            if (selector == null)
                throw new ArgumentNullException("selector");

            selector.SetValue(CommandProperty, command);
        }
Esempio n. 3
0
 protected override UIElement CreateEditor()
 {
     Selector = CreateSelector();
     Selector.VerticalAlignment = VerticalAlignment.Center;
     Selector.SelectionChanged += Selector_SelectionChanged;
     return Selector;
 }
Esempio n. 4
0
		protected SelectorAutomationPeer (Selector owner) : base (owner)
		{
			owner.SelectionChanged += (o, e) => {
				// Selection Pattern Automation Events
				// - CanSelectMultiple and IsSelectionRequired not raised because value doesn't change/
				// - Selection.SelectionProperty:
				RaisePropertyChangedEvent (SelectionPatternIdentifiers.SelectionProperty,
				                           GetProviderArrayFromPeer (oldSelectedPeer),
							   GetProviderArrayFromPeer (GetSelectedAutomationPeer ()));

				// SelectionItem Pattern Automation Events
				// (Only raising SelectionItemPatternOnElementSelected because Selector 
				//  supports one selected item)
				if (oldSelectedPeer != null) // Old Selected Item
					oldSelectedPeer.RaisePropertyChangedEvent (SelectionItemPatternIdentifiers.IsSelectedProperty,
					                                           true, 
										   false);
				oldSelectedPeer = GetSelectedAutomationPeer ();
				if (oldSelectedPeer != null) { // New Selected Item
					oldSelectedPeer.RaisePropertyChangedEvent (SelectionItemPatternIdentifiers.IsSelectedProperty,
					                                           false, 
										   true);
					oldSelectedPeer.RaiseAutomationEvent (AutomationEvents.SelectionItemPatternOnElementSelected);
				}
			};
			oldSelectedPeer = GetSelectedAutomationPeer ();
		}
        protected override void Adapt(IRegion region, Selector regionTarget)
        {
            if (!(regionTarget is OutlookBarControl))
                throw new ArgumentException(Resources.RegionTargetNotValidException);

            base.Adapt(region, regionTarget);
        }
Esempio n. 6
0
        public static void SetCommandParameter(Selector selector, object parameter)
        {
            if (selector == null)
                throw new ArgumentNullException("selector");

            selector.SetValue(CommandParameterProperty, parameter);
        }
Esempio n. 7
0
        public static void SetComboItem(System.Windows.Controls.Primitives.Selector combo, int item)
        {
            if (combo == null)
            {
                return;
            }

            foreach (object it in combo.Items)
            {
                object tag = null;

                if (it is ComboBoxItem)
                {
                    tag = ((ComboBoxItem)it).Tag;
                }
                else
                {
                    continue;
                }

                try
                {
                    if (tag != null && (int)tag == item)
                    {
                        combo.SelectedItem = it;
                        return;
                    }
                }
                catch (Exception e)
                {
                }
            }
        }
Esempio n. 8
0
        public static void SetComboItem(System.Windows.Controls.Primitives.Selector combo, object obj)
        {
            if (combo == null)
            {
                return;
            }

            foreach (object it in combo.Items)
            {
                object tag = null;

                if (it is ComboBoxItem)
                {
                    tag = ((ComboBoxItem)it).Tag;
                }
                else
                {
                    continue;
                }

                if (obj is string)                  // Для строк
                {
                    if (tag.ToString() == obj.ToString())
                    {
                        combo.SelectedItem = it;
                        return;
                    }
                }
                else if (tag == obj)
                {
                    combo.SelectedItem = it;
                    return;
                }
            }
        }
 /// <summary>
 /// </summary>
 /// <param name="listView"> </param>
 /// <param name="key"> </param>
 private static string GetValueBySelectedItem(Selector listView, string key)
 {
     var type = listView.SelectedItem.GetType();
     var property = type.GetProperty(key);
     return property.GetValue(listView.SelectedItem, null)
                    .ToString();
 }
Esempio n. 10
0
        public static ICommand GetCommand(Selector selector)
        {
            if (selector == null)
                throw new ArgumentNullException("selector");

            return selector.GetValue(CommandProperty) as ICommand;
        }
Esempio n. 11
0
        public static object GetCommandParameter(Selector selector)
        {
            if (selector == null)
                throw new ArgumentNullException("selector");

            return selector.GetValue(CommandParameterProperty);
        }
Esempio n. 12
0
 private static void SelectTabItem(Selector tabControl, object tabItemHeader)
 {
     if (tabItemHeader == null) return;
     foreach (var tabItem in tabControl.Items.Cast<object>().Where(item => item.GetType() == typeof (TabItem)).Cast<TabItem>().Where(tabItem => Equals(tabItem.Header, tabItemHeader)))
     {
         tabControl.SelectedItem = tabItem;
     }
 }
 private void DecrementSelection(Selector itemsSelector)
 {
     if (itemsSelector.Items == null || !itemsSelector.HasItems || itemsSelector.SelectedIndex <= 0)
     {
         return;
     }
     itemsSelector.SelectedIndex--;
 }
Esempio n. 14
0
 public ItemCommand(Selector selector, EventHandler<ItemCanExecuteEventArgs> canExecute, EventHandler<ItemExecutedEventArgs> executed)
 {
     if (selector == null)
         throw new ArgumentNullException("selector");
     Selector = selector;
     Selector.SelectionChanged += Selector_SelectionChanged;
     Executed = executed;
     canExecuteHandler = canExecute;
 }
Esempio n. 15
0
		public static void SetFocus(Selector selector, object obj, DispatcherPriority prio) {
			selector.Dispatcher.BeginInvoke(prio, new Action(() => {
				if (selector.SelectedItem == obj) {
					var item = selector.ItemContainerGenerator.ContainerFromItem(obj) as IInputElement;
					if (item != null)
						item.Focus();
				}
			}));
		}
        private static void TryCleanUpOldItem(Selector selector)
        {
            selector.SelectionChanged -= SelectorSelectionChanged;  // Remove a previously added event handler.

            var item = multiSelectorWithObservableList.FirstOrDefault(x => x.Item1.Selector == selector);
            if (item == null) { return; }

            multiSelectorWithObservableList.Remove(item);
            CollectionChangedEventManager.RemoveHandler(item.Item2, ListCollectionChanged);    
        }
Esempio n. 17
0
 public SelectedItemsSync (Selector selector, IList modelSelectedItems)
 {
     if (!(selector is MultiSelector) && !(selector is ListBox))
         throw new ArgumentException(ErrorUnsupportedSelectorType.Fmt(Selector.GetTypeFullName()), "selector");
     if (modelSelectedItems != null && !(modelSelectedItems is INotifyCollectionChanged))
         throw new ArgumentException("Selected items collection must implement INotifyCollectionChanged", "modelSelectedItems");
     Selector = selector;
     _modelSelectedItems = modelSelectedItems;
     AttachSelectedItems();
 }
Esempio n. 18
0
        private static SelectorSelectionChangedCommandBehavior GetOrCreateBehavior(Selector selector)
        {
            var behavior = selector.GetValue(SelectionChangedCommandBehaviorProperty) as SelectorSelectionChangedCommandBehavior;
            if (behavior == null)
            {
                behavior = new SelectorSelectionChangedCommandBehavior(selector);
                selector.SetValue(SelectionChangedCommandBehaviorProperty, behavior);
            }

            return behavior;
        }
Esempio n. 19
0
 private static void SelectedItems_Changed (Selector selector, DpChangedEventArgs<IList> e)
 {
     SelectedItemsSync sync = GetSelectedItemsSync(selector);
     if (sync != null) {
         sync.ModelSelectedItems = e.NewValue;
     }
     else {
         SetSelectedItemsSync(selector, new SelectedItemsSync(selector, e.NewValue));
         selector.Unloaded += Selector_Unloaded;
     }
 }
Esempio n. 20
0
        private static GenericSelectCommandBehavior GetOrCreateBehavior(Selector selector)
        {
            var behavior = selector.GetValue(SelectCommandBehaviorProperty) as GenericSelectCommandBehavior;
            if (behavior == null)
            {
                behavior = new GenericSelectCommandBehavior(selector);
                selector.SetValue(SelectCommandBehaviorProperty, behavior);
            }

            return behavior;
        }
Esempio n. 21
0
 public override void OnApplyTemplate()
 {
     base.OnApplyTemplate();
     CommandPopulateComplete = new RelayCommand(PopulateComplete);
     _textBox = GetTemplateChild("Text") as TextBox;
     _selector = GetTemplateChild("Selector") as Selector;
     if (_selector == null)
     {
         return;
     }
     _selector.RenderTransform = new TranslateTransform { Y = PopupVerticalOffset };
 }
Esempio n. 22
0
 public ColumnBinderSelector(Selector tb)
     : base(tb)
 {
     Binding = (BindingExpression)tb.SetBinding(Selector.SelectedItemProperty,
         new System.Windows.Data.Binding("Value")
         {
             Source = this,
             Mode = System.Windows.Data.BindingMode.TwoWay,
             ValidatesOnExceptions = true,
             NotifyOnValidationError = true
         });
 }
Esempio n. 23
0
        public static Dictionary <object, bool?> ToDictionary(this System.Windows.Controls.Primitives.Selector selector)
        {
            //if (sender is not System.Windows.Controls.Primitives.Selector selector)
            //{
            //    throw new System.Exception("sdf4 fdgdgp;p;p");
            //}

            //if (string.IsNullOrEmpty(selector.SelectedValuePath) == false ||
            //    string.IsNullOrEmpty(selector.DisplayMemberPath) == false)
            //{
            var items  = selector.ItemsOfType <CheckBox>().ToArray();
            var output = items.Where(a => a is { Tag: { } tag }).ToDictionary(a => a.Tag, a => a.IsChecked);
Esempio n. 24
0
            public Behaviour(Selector selector)
            {
                this.selector = selector;
                this.selector.SelectionChanged += (sender, e) =>
                {
                    var element = sender as UIElement;
                    if (sender == null) throw new NullReferenceException("Sender is null");

                    var command = (ICommand)element.GetValue(SelectorBehaviour.SelectionChangedProperty);

                    if (command.CanExecute(e.AddedItems)) { command.Execute(e.AddedItems); }
                };
            }
        /// <summary>
        ///     Attaches all necesary event handlers, sets bindings an properties
        /// </summary>
        /// <param name="region">Region to attach to</param>
        /// <param name="regionHost">Region host to attach to</param>
        /// <exception cref="ArgumentNullException">
        ///     When <paramref name="region"/> or <paramref name="regionHost"/> is null
        /// </exception>
        /// <exception cref="InvalidOperationException">
        ///     When <paramref name="region"/> or <paramref name="regionHost"/> do not 
        ///     meet requirements of this <see cref="IRegionBehavior"/>
        /// </exception>
        public void Attach(IRegion region, DependencyObject regionHost)
        {
            if (region == null) throw new ArgumentNullException("region");
            if (regionHost == null) throw new ArgumentNullException("regionHost");
            if (!(regionHost is Selector))
                throw new InvalidOperationException(
                    "Only Selector and MultiSelector controls can be enchanced by this behavior");

            _control = (Selector) regionHost;
            _region = region;

            _control.SelectionChanged += ControlSelectionChanged;
            _region.ActiveViews.CollectionChanged += RegionActiveViewsChanged;
        }
        private static string GetSelectedValueFromVersionComboBox(Selector versionComboBox)
        {
            var selectedValue = "";
            if (versionComboBox == null) return selectedValue;

            var selectedItem = versionComboBox.SelectedItem as ComboBoxItem;

            if (selectedItem != null)
            {
                selectedValue = selectedItem.Content as string;
            }

            return selectedValue;
        }
Esempio n. 27
0
        public static object GetComboItem(System.Windows.Controls.Primitives.Selector combo)
        {
            if (combo.SelectedItem == null)
            {
                return(null);
            }

            return(combo.SelectedIndex);

/*			if (combo.SelectedItem is ComboBoxItem)
 *                              return ((ComboBoxItem)combo.SelectedItem).Tag;
 *                      else
 *                              return null;
 */
        }
Esempio n. 28
0
        public bool FillApiComboBox(Selector lst,string api)
        {
            if (lst == null) return false;

            lst.Items.Clear();
            var index = 0;
            foreach (var remotePlugin in _remotePlugins)
            {
                var index2 = lst.Items.Add(remotePlugin.Name);
                if (remotePlugin.Name == api)
                    index = index2;
            }
            lst.SelectedIndex = index;
            return true;
        }
Esempio n. 29
0
        public override void OnApplyTemplate()
        {
            _Selector = (Selector)GetTemplateChild("PART_Selector");
            _Add = (Button)GetTemplateChild("PART_Add");
            _Remove = (Button)GetTemplateChild("PART_Remove");
            _Clear = (Button)GetTemplateChild("PART_Clear");

            _Add.Click += _Add_Click;
            _Remove.Click += _Remove_Click;
            _Clear.Click += _Clear_Click;

            _Remove.SetBinding(UIElement.IsEnabledProperty, new Binding("SelectedItem")
            {
                Source = _Selector,
                Converter = new IsNullToBooleanValueConverter(),
                ConverterParameter = false
            });
        }
Esempio n. 30
0
        protected override void OnVisualParentChanged(DependencyObject oldParent)
        {
            ParentSelector = this.TryFindParent<Selector>();

            if (ParentSelector!=null)
            {

                IsKeyboardFocusWithinChanged += OnIsKeyboardFocusWithinChanged;

                MouseRightButtonUp += RightClickComboMouseRightButtonUp;
                MouseLeave += RightClickComboMouseLeave;
                PreviewMouseRightButtonDown += RightClickComboPreviewMouseRightButtonDown;
                PreviewMouseLeftButtonDown += OnPreviewMouseLeftButtonDown;

                SetBinding(SelectedItemProperty, new Binding { Path = new PropertyPath("SelectedItem"), Source = ParentSelector, TargetNullValue = Items[0]});
            }

            base.OnVisualParentChanged(oldParent);
        }
        public SelectionAdapter(Control editor, Selector itemsSelector)
        {
            if (editor == null)
            {
                throw new ArgumentNullException(nameof(editor));
            }
            if (itemsSelector == null)
            {
                throw new ArgumentNullException(nameof(itemsSelector));
            }
            this.editor = editor;
            this.itemsSelector = itemsSelector;

            var selectedItemChanged = Observable
               .FromEventPattern<SelectionChangedEventHandler, EventArgs>(x => itemsSelector.SelectionChanged += x, x => itemsSelector.SelectionChanged -= x)
               .Select(x => itemsSelector.SelectedItem)
               .DistinctUntilChanged()
               .Publish();

            Observable.FromEventPattern<KeyEventHandler, KeyEventArgs>(x => editor.PreviewKeyDown += x, x => editor.PreviewKeyDown -= x)
                .Subscribe((x) => ItemsSelectorOnPreviewKeyDown(itemsSelector, x.EventArgs));

            Observable.FromEventPattern<KeyEventHandler, KeyEventArgs>(x => editor.PreviewKeyDown += x, x => editor.PreviewKeyDown -= x)
                .Subscribe((x) => ItemsSelectorOnPreviewKeyDownHandleCommit(itemsSelector, x.EventArgs));

            Observable.FromEventPattern<MouseButtonEventHandler, MouseEventArgs>(x => itemsSelector.PreviewMouseDown += x, x => itemsSelector.PreviewMouseDown -= x)
                .Select(_ => selectedItemChanged.Take(1).Subscribe(() => CommitSelection(itemsSelector)))
                .Subscribe();

            SelectedItemChanged = Observable
              .FromEventPattern<EventHandler, EventArgs>(x => itemsSelector.Items.CurrentChanged += x, x => itemsSelector.Items.CurrentChanged -= x)
              .Select(x => itemsSelector.Items.CurrentItem)
              .DistinctUntilChanged()
              .ToSuspendable();

            selectedItemChanged.Connect();
        }
 /// <summary>
 /// Initializes a new instance of the SelectorSelectionAdapter class.
 /// </summary>
 /// <param name="selector">A selector control instance.</param>
 public SelectorSelectionAdapter(Selector selector)
 {
     SelectorControl = selector;
 }
 private void _InitParts()
 {
     _TextBox = (TextBox)this.GetTemplateChild("PART_TextBox");
     _Selector = (Selector)this.GetTemplateChild("PART_Selector");
     _Popup = (Popup)this.GetTemplateChild("PART_PopupPanel");
 }
 public static void RemoveListener( Selector source, IWeakEventListener listener )
 {
   CurrentManager.ProtectedRemoveListener( source, listener );
 }