private static void IsSelectedChangeCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            MontuBoxItem ctrl   = d as MontuBoxItem;
            bool         oldVal = (bool)e.OldValue;
            bool         newVal = (bool)e.NewValue;

            ctrl.OnSelectedChanged(oldVal, newVal);
        }
Ejemplo n.º 2
0
        private void RemoveSelectedItem(MontuBoxItem ctrl)
        {
            MontuSelectedItems.Remove(ctrl.DataContext);
            var tempCollection = SelectedItems as ObservableCollection <object>;

            if (tempCollection != null)
            {
                tempCollection.Remove(ctrl.DataContext);
            }
        }
Ejemplo n.º 3
0
        protected virtual void OnItemsSourceChanged(IEnumerable oldValue, IEnumerable newValue)
        {
            MontuItems.Clear();
            ClearSelectedItem();

            if (MontuContentPresenter != null)
            {
                MontuContentPresenter.Content = null;
            }

            if (newValue != null)
            {
                foreach (var item in newValue)
                {
                    var mI = new MontuBoxItem()
                    {
                        Content       = item,
                        Style         = MontuBoxItemStyle,
                        CheckBoxStyle = CheckboxStyle,
                        DataContext   = item
                    };

                    mI.IsSelectedChanged -= OnMontuItemIsSelectedChanged;

                    MontuItems.Add(mI);

                    mI.IsSelectedChanged += OnMontuItemIsSelectedChanged;
                }

                var x = newValue as INotifyCollectionChanged;
                if (x != null)
                {
                    x.CollectionChanged -= OnItemCollectionChanged;
                    x.CollectionChanged += OnItemCollectionChanged;
                }
            }

            if (oldValue != null)
            {
                var x = oldValue as INotifyCollectionChanged;
                if (x != null)
                {
                    x.CollectionChanged -= OnItemCollectionChanged;
                }
            }
        }
Ejemplo n.º 4
0
        private void OnItemCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == NotifyCollectionChangedAction.Add && e.NewItems != null)
            {
                foreach (var item in e.NewItems)
                {
                    var mI = new MontuBoxItem()
                    {
                        Content       = item,
                        Style         = MontuBoxItemStyle,
                        CheckBoxStyle = CheckboxStyle,
                        DataContext   = item
                    };

                    mI.IsSelectedChanged -= OnMontuItemIsSelectedChanged;

                    MontuItems.Add(mI);

                    mI.IsSelectedChanged += OnMontuItemIsSelectedChanged;
                }
            }
            else if (e.Action == NotifyCollectionChangedAction.Remove && e.OldItems != null)
            {
                foreach (var item in e.OldItems)
                {
                    var removeItem = MontuItems.Where(i => i.Content.Equals(item))
                                     .FirstOrDefault();
                    if (removeItem != null)
                    {
                        removeItem.IsSelectedChanged -= OnMontuItemIsSelectedChanged;
                        MontuItems.Remove(removeItem);
                        RemoveSelectedItem(removeItem);
                    }
                }
            }
        }