コード例 #1
0
        protected override IScriptCommand executeInner(ParameterDic pm, ItemsControl ic, RoutedEventArgs evnt, IUIInput input, IList <IUIInputProcessor> inpProcs)
        {
            if (!_update)
            {
                var selectedIdList = pm.ContainsKey("SelectedIdList") ? pm["SelectedIdList"] as List <int>
                    : new List <int>();

                logger.Debug(String.Format("Highlighting {0} items", selectedIdList.Count()));

                for (int i = 0; i < ic.Items.Count; i++)
                {
                    DependencyObject item = ic.ItemContainerGenerator.ContainerFromIndex(i);
                    if (item != null)
                    {
                        bool isSelecting = selectedIdList.Contains(i);
                        //UIEventHubProperties.SetIsSelecting(item, isSelecting);
                        var selectable = (item as FrameworkElement).DataContext as ISelectable;
                        if (selectable != null)
                        {
                            selectable.IsSelecting = isSelecting;
                        }
                    }
                }
            }
            else
            {
                List <object> unselectedList   = pm["UnselectedList"] as List <object>;
                List <int>    unselectedIdList = pm["UnselectedIdList"] as List <int>;

                List <object> selectedList   = pm["SelectedList"] as List <object>;
                List <int>    selectedIdList = pm["SelectedIdList"] as List <int>;

                logger.Debug(String.Format("Highlighting {0} items", selectedIdList.Count()));
                logger.Debug(String.Format("De-highlighting {0} items", unselectedIdList.Count()));

                for (int i = 0; i < ic.Items.Count; i++)
                {
                    DependencyObject ele  = ic.ItemContainerGenerator.ContainerFromIndex(i);
                    ISelectable      item = ic.Items[i] as ISelectable;


                    if (ele != null)
                    {
                        bool isSelecting = UIEventHubProperties.GetIsSelecting(ele);
                        if (isSelecting && unselectedList.Contains(ele))
                        {
                            item.IsSelecting = false;
                        }
                        //AttachedProperties.SetIsSelecting(item, false);
                        else if (!isSelecting && selectedList.Contains(ele))
                        {
                            item.IsSelecting = true;
                        }
                        //AttachedProperties.SetIsSelecting(ele, true);
                    }
                }
            }

            return(NextCommand);
        }
コード例 #2
0
        protected override IScriptCommand executeInner(ParameterDic pm, ItemsControl ic,
                                                       RoutedEventArgs evnt, IUIInput input, IList <IUIInputProcessor> inpProcs)
        {
            Point         posRelToScp    = pm.GetValue <Point>(CurrentRelativePositionKey);
            var           startSelected  = UIEventHubProperties.GetStartSelectedItem(ic);
            List <object> selectedList   = new List <object>();
            List <int>    selectedIdList = new List <int>();
            var           scp            = ControlUtils.GetScrollContentPresenter(ic);

            var currentSelected = UITools.GetSelectedListBoxItem(scp, posRelToScp);

            if (startSelected != null && currentSelected != null)
            {
                int startIdx = ic.ItemContainerGenerator.IndexFromContainer(startSelected);
                int endIdx   = ic.ItemContainerGenerator.IndexFromContainer(currentSelected);

                for (int i = Math.Min(startIdx, endIdx); i <= Math.Max(startIdx, endIdx); i++)
                {
                    selectedList.Add(ic.Items[i]);
                    selectedIdList.Add(i);
                }
            }

            //UpdateStartSelectedItems, or clear it if no longer selecting.
            if (UIEventHubProperties.GetIsSelecting(ic))
            {
                if (UIEventHubProperties.GetStartSelectedItem(ic) == null)
                {
                    var itemUnderMouse = UITools.GetSelectedListBoxItem(scp, posRelToScp);
                    UIEventHubProperties.SetStartSelectedItem(ic, itemUnderMouse);
                }
            }
            else
            {
                UIEventHubProperties.SetStartSelectedItem(ic, null);
            }

            if (UIEventHubProperties.GetIsSelecting(ic))
            {
                if (UIEventHubProperties.GetStartSelectedItem(ic) == null)
                {
                    UITools.SetItemUnderMouseToAttachedProperty(ic, posRelToScp,
                                                                UIEventHubProperties.StartSelectedItemProperty);
                }
            }

            pm.SetValue(SelectedListKey, selectedList);
            pm.SetValue(SelectedIdListKey, selectedIdList);
            logger.Debug(String.Format("Selected = {0}", selectedIdList.Count()));
            return(NextCommand);
        }
コード例 #3
0
        protected override Script.IScriptCommand executeInner(ParameterDic pm, ItemsControl ic, RoutedEventArgs evnt, IUIInput input, IList <IUIInputProcessor> inpProcs)
        {
            var  scp         = ControlUtils.GetScrollContentPresenter(ic);
            bool isSelecting = UIEventHubProperties.GetIsSelecting(ic);

            FindSelectionMode fsMode = FindSelectionMode.HitTest;

            IChildInfo icInfo = UITools.FindVisualChild <Panel>(scp) as IChildInfo;

            if (icInfo != null)
            {
                fsMode = FindSelectionMode.IChildInfo;
            }
            else
            if (ic is ListView && (ic as ListView).View is GridView)
            {
                fsMode = FindSelectionMode.GridView;
            }

            logger.Debug(String.Format("SelectionMode = {0}", fsMode));
            pm.SetValue(FindSelectionModeKey, fsMode, false);

            return(NextCommand);
        }
コード例 #4
0
        protected override Script.IScriptCommand executeInner(ParameterDic pm, ItemsControl sender,
                                                              RoutedEventArgs evnt, IUIInput input, IList <IUIInputProcessor> inpProcs)
        {
            var scp = ControlUtils.GetScrollContentPresenter(sender);

            if (scp != null)
            {
                AdornerLayer adornerLayer = ControlUtils.GetAdornerLayer(sender);

                switch (AdornerMode)
                {
                case UIEventHub.AdornerMode.Attach:
                    if (adornerLayer == null)
                    {
                        return(ResultCommand.Error(new Exception("Adorner layer not found.")));
                    }
                    if (UIEventHubProperties.GetSelectionAdorner(scp) == null)
                    {
                        Window parentWindow = UITools.FindAncestor <Window>(sender);

                        Point scpPos = scp.TranslatePoint(new Point(0, 0), sender);

                        //Create and register adorner.
                        SelectionAdorner adorner = new SelectionAdorner(scp)
                        {
                            //AdjustVector = new Vector(-scpPos.X, -scpPos.Y)
                        };
                        pm.SetValue(SelectionAdornerKey, adorner);
                        UIEventHubProperties.SetSelectionAdorner(scp, adorner);
                        UIEventHubProperties.SetLastScrollContentPresenter(sender, scp);     //For used when detach.

                        adornerLayer.Add(adorner);
                    }
                    break;

                case UIEventHub.AdornerMode.Detach:

                    var lastScp     = UIEventHubProperties.GetLastScrollContentPresenter(sender); //For used when detach.
                    var lastAdorner = UIEventHubProperties.GetSelectionAdorner(scp);
                    if (lastAdorner != null)
                    {
                        adornerLayer.Remove(lastAdorner);
                    }

                    UIEventHubProperties.SetLastScrollContentPresenter(sender, null);
                    UIEventHubProperties.SetSelectionAdorner(scp, null);
                    pm.SetValue <Object>(SelectionAdornerKey, null);
                    break;

                case UIEventHub.AdornerMode.Update:
                    var updateAdorner = pm.GetValue <SelectionAdorner>(SelectionAdornerKey) ??
                                        UIEventHubProperties.GetSelectionAdorner(scp);

                    if (updateAdorner == null)
                    {
                        return(ResultCommand.Error(new Exception("Adorner not found.")));
                    }

                    updateAdorner.IsSelecting = UIEventHubProperties.GetIsSelecting(sender);
                    Point startAdjusted = pm.GetValue <Point>("{StartPosition}");
                    Point current       = pm.GetValue <Point>(CurrentPositionKey);
                    updateAdorner.SetValue(SelectionAdorner.StartPositionProperty, startAdjusted);
                    updateAdorner.SetValue(SelectionAdorner.EndPositionProperty, current);
                    break;
                }
            }
            return(NextCommand);
        }