protected override IScriptCommand executeInner(ParameterDic pm, ItemsControl ic, RoutedEventArgs evnt, IUIInput input, IList <IUIInputProcessor> inpProcs)
        {
            var        scp    = ControlUtils.GetScrollContentPresenter(ic);
            IChildInfo icInfo = UITools.FindVisualChild <Panel>(scp) as IChildInfo;

            if (icInfo == null)
            {
                return(ResultCommand.Error(new NotSupportedException()));
            }

            Rect          selectionBound = pm.GetValue <Rect>(SelectionBoundAdjustedKey);
            List <object> selectedList   = new List <object>();
            List <int>    selectedIdList = new List <int>();

            for (int i = 0; i < ic.Items.Count; i++)
            {
                if (icInfo.GetChildRect(i).IntersectsWith(selectionBound))
                {
                    selectedList.Add(ic.Items[i]);
                    selectedIdList.Add(i);
                }
            }

            pm.SetValue(SelectedListKey, selectedList);
            pm.SetValue(SelectedIdListKey, selectedIdList);
            logger.Debug(String.Format("Selected = {0}", selectedIdList.Count()));

            return(NextCommand);
        }
        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);
        }
Esempio n. 3
0
        static void UpdateSelection(ScrollContentPresenter p, Rect selectionBounds, bool highlightOnly)
        {
            try
            {
                ListView lvControl = UITools.FindAncestor <ListView>(p);
                if (lvControl != null)
                {
                    IChildInfo icInfo = UITools.FindVisualChild <Panel>(p) as IChildInfo;

                    List <object> newList    = new List <object>();
                    List <int>    newIntList = new List <int>();

                    if (icInfo != null)
                    {
                        for (int i = 0; i < lvControl.Items.Count; i++)
                        {
                            if (icInfo.GetChildRect(i).IntersectsWith(selectionBounds))
                            {
                                newList.Add(lvControl.Items[i]);
                                newIntList.Add(i);
                            }
                        }
                    }
                    else
                    //0.4 For GridView, only support selection if drag occur inside the first column
                    if (lvControl.View is GridView)
                    {
                        Point curPos = (Point)PositionCheck(GetSelectionAdorner(p), Mouse.GetPosition(p));

                        if ((lvControl.View as GridView).Columns.Count > 0)
                        {
                            double col0width = (lvControl.View as GridView).Columns[0].ActualWidth;
                            if (curPos.X < col0width || GetStartPosition(p).X < col0width)
                            {
                                if (_firstSelectedItem == null)
                                {
                                    _firstSelectedItem = getSelectedItem(p, curPos);
                                }
                                if (getSelectedItem(p, curPos) != null)
                                {
                                    _curSelectedItem = getSelectedItem(p, curPos);
                                }

                                if (_firstSelectedItem != null && _curSelectedItem != null)
                                {
                                    int startIdx = lvControl.ItemContainerGenerator.IndexFromContainer(_firstSelectedItem);
                                    int endIdx   = lvControl.ItemContainerGenerator.IndexFromContainer(_curSelectedItem);


                                    for (int i = Math.Min(startIdx, endIdx); i <= Math.Max(startIdx, endIdx); i++)
                                    {
                                        newList.Add(lvControl.Items[i]);
                                        newIntList.Add(i);
                                    }
                                }
                            }
                        }
                    }

                    if (highlightOnly)
                    {
                        SetHighlightCount(lvControl, newIntList.Count);
                        HighlightItems(lvControl, newIntList);
                    }
                    else
                    {
                        SetHighlightCount(lvControl, 0);
                        UnhighlightItems(lvControl);
                        UpdateSelectedItems(lvControl, newList);
                    }
                }
            }
            catch { }
        }