Exemplo n.º 1
0
        /// <summary>
        /// tries to get ItemsControlFromItemContainer
        /// </summary>
        /// <param name="e"></param>
        protected override void OnTemplateApplied(TemplateAppliedEventArgs e)
        {
            base.OnTemplateApplied(e);
#warning does this work?
            var windowCommands = ItemsControlExtensions.ItemsControlFromItemContainer(this) as WindowCommands;
            this.SetValue(WindowCommandsItem.ParentWindowCommandsProperty, windowCommands);
        }
Exemplo n.º 2
0
        private void treeView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (e.OriginalSource is System.Windows.Controls.Grid)
            {
                return;
            }

            TreeViewItemArg arg = getSelectedArg();

            if (arg == null || arg.type != ItemType.Variable || !(arg.data as Var).isClass)
            {
                return;
            }

            string className = (arg.data as Var).type;

            foreach (Class c in cfg.classes)
            {
                if (c.name == className)
                {
                    c.item.IsExpanded = true;
                    c.item.IsSelected = true;
                    ItemsControlExtensions.ScrollToCenterOfView(treeView1, c.item);
                    break;
                }
            }

            tabControl.SelectedIndex = TabTypeClass;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Scroll based on current position.
        /// </summary>
        /// <param name="Position"></param>
        void Scroll(Point Position)
        {
            double HorizontalPosition = Position.X, VerticalPosition = Position.Y;

            var ScrollOffset    = ItemsControlExtensions.GetDragScrollOffset(ItemsControl);
            var ScrollTolerance = ItemsControlExtensions.GetDragScrollTolerance(ItemsControl);

            //Cursor is at top, scroll up.
            if (VerticalPosition < ScrollTolerance)
            {
                ScrollViewer.ScrollToVerticalOffset(ScrollViewer.VerticalOffset - ScrollOffset);
            }
            //Cursor is at bottom, scroll down.
            else if (VerticalPosition > ItemsControl.ActualHeight - ScrollTolerance) //Bottom of visible list?
            {
                ScrollViewer.ScrollToVerticalOffset(ScrollViewer.VerticalOffset + ScrollOffset);
            }
            //Cursor is at left, scroll left.
            else if (HorizontalPosition < ScrollTolerance)
            {
                ScrollViewer.ScrollToHorizontalOffset(ScrollViewer.HorizontalOffset - ScrollOffset);
            }
            //Cursor is at right, scroll right.
            else if (HorizontalPosition > ItemsControl.ActualWidth - ScrollTolerance)
            {
                ScrollViewer.ScrollToHorizontalOffset(ScrollViewer.HorizontalOffset + ScrollOffset);
            }
        }
Exemplo n.º 4
0
        private void UpdateOrientation()
        {
            if (this.Initializing || this.Items.Count <= 0)
            {
                return;
            }
            StackPanel stackPanel = VisualTreeHelper.GetParent((DependencyObject)this.Items[0]) as StackPanel;

            if (stackPanel != null && stackPanel.Orientation != this.Orientation)
            {
                stackPanel.Orientation = this.Orientation;
                ScrollViewer scrollHost = ItemsControlExtensions.GetScrollHost((ItemsControl)this);
                if (scrollHost != null)
                {
                    scrollHost.HorizontalScrollBarVisibility = this.Orientation == Orientation.Vertical ? ScrollBarVisibility.Disabled : ScrollBarVisibility.Auto;
                    scrollHost.VerticalScrollBarVisibility   = this.Orientation == Orientation.Horizontal ? ScrollBarVisibility.Disabled : ScrollBarVisibility.Auto;
                }
            }
            foreach (object obj in (IEnumerable)this.Items)
            {
                LegendItem legendItem = obj as LegendItem;
                if (legendItem != null && legendItem.Title != null)
                {
                    legendItem.Title.TextTrimming = this.Orientation == Orientation.Vertical ? TextTrimming.WordEllipsis : TextTrimming.None;
                }
            }
        }
Exemplo n.º 5
0
        internal void ChangeViewPoint(bool isforward)
        {
            ScrollViewer scrollHost = ItemsControlExtensions.GetScrollHost((ItemsControl)this);

            if (scrollHost == null)
            {
                return;
            }
            if (isforward)
            {
                if (this.Orientation == Orientation.Vertical)
                {
                    scrollHost.PageDown();
                }
                else
                {
                    scrollHost.PageRight();
                }
            }
            else if (this.Orientation == Orientation.Vertical)
            {
                scrollHost.PageUp();
            }
            else
            {
                scrollHost.PageLeft();
            }
        }
Exemplo n.º 6
0
        internal bool SetFocusToItem(LegendItem item)
        {
            bool flag = false;

            if (item != null)
            {
                if (!item.IsInLegendVisibleArea(this))
                {
                    ScrollViewer scrollHost = ItemsControlExtensions.GetScrollHost((ItemsControl)this);
                    if (scrollHost != null)
                    {
                        ScrollViewerExtensions.ScrollIntoView(scrollHost, (FrameworkElement)item, 0.0, 0.0, (Duration)TimeSpan.Zero.Duration());
                    }
                }
                flag = item.Focus();
            }
            return(flag);
        }
Exemplo n.º 7
0
        private void doSearch(int searchId, String searchName)
        {
            if (tabControl.SelectedIndex == TabTypeDefine)
            {
                foreach (Group g in cfg.groups)
                {
                    if (g.name.ToLower() == searchName.ToLower())
                    {
                        g.item.IsExpanded = true;
                        g.item.IsSelected = true;
                        ItemsControlExtensions.ScrollToCenterOfView(treeView0, g.item);
                        return;
                    }

                    foreach (Msg m in g.msgs)
                    {
                        if (m.idValue == searchId || m.name.ToLower() == searchName.ToLower())
                        {
                            g.item.IsExpanded = true;
                            m.item.IsExpanded = true;
                            m.item.IsSelected = true;
                            ItemsControlExtensions.ScrollToCenterOfView(treeView0, m.item);
                            return;
                        }

                        foreach (Var v in m.vars)
                        {
                            if (v.name.ToLower() == searchName.ToLower())
                            {
                                g.item.IsExpanded = true;
                                m.item.IsExpanded = true;
                                v.item.IsSelected = true;
                                ItemsControlExtensions.ScrollToCenterOfView(treeView0, v.item);
                                return;
                            }
                        }
                    }
                }
            }
            else if (tabControl.SelectedIndex == TabTypeClass)
            {
                foreach (Class c in cfg.classes)
                {
                    if (c.name.ToLower() == searchName.ToLower())
                    {
                        c.item.IsExpanded = true;
                        c.item.IsSelected = true;
                        ItemsControlExtensions.ScrollToCenterOfView(treeView1, c.item);
                        return;
                    }

                    foreach (Var v in c.vars)
                    {
                        if (v.name.ToLower() == searchName.ToLower())
                        {
                            c.item.IsExpanded = true;
                            v.item.IsExpanded = true;
                            v.item.IsSelected = true;
                            ItemsControlExtensions.ScrollToCenterOfView(treeView1, v.item);
                            return;
                        }
                    }
                }
            }
        }
Exemplo n.º 8
0
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            var provideValueTarget = serviceProvider.GetService(typeof(IProvideValueTarget)) as IProvideValueTarget;

            if (provideValueTarget == null)
            {
                return(TimeSpan.Zero);
            }

            if (provideValueTarget.TargetObject != null &&
                provideValueTarget.TargetObject.GetType().FullName == "System.Windows.SharedDp")
            {
                //we are inside a template, return this, so we can re-evaluate later...
                return(this);
            }

            var element = provideValueTarget?.TargetObject as DependencyObject;

            if (element == null)
            {
                return(TimeSpan.Zero);
            }

            var itemsControl = ItemsControl.ItemsControlFromItemContainer(element);

            if (itemsControl == null)
            {
                DependencyObject ancestor = element;
                while (ancestor != null && itemsControl == null)
                {
                    ancestor     = VisualTreeHelper.GetParent(ancestor);
                    itemsControl = ItemsControl.ItemsControlFromItemContainer(ancestor);
                }
            }
            if (itemsControl == null)
            {
                return(TimeSpan.Zero);
            }

            var isOwnContainer         = ItemsControlExtensions.IsItemItsOwnContainer(itemsControl, element);
            DependencyObject container = isOwnContainer
                ? element
                : itemsControl.ItemContainerGenerator.ContainerFromItem(element);

            if (container == null)
            {
                var dataContext = (element as FrameworkElement)?.DataContext;
                if (dataContext != null)
                {
                    container = itemsControl.ItemContainerGenerator.ContainerFromItem(dataContext);
                }
            }

            if (container == null)
            {
                return(TimeSpan.Zero);
            }

            var multiplier = itemsControl.ItemContainerGenerator.IndexFromContainer(container);

            if (multiplier == -1) //container generation may not have completed
            {
                multiplier = itemsControl.Items.IndexOf(element);
            }

            if (multiplier == -1) //still not found, repeat now using datacontext
            {
                var frameworkElement = element as FrameworkElement;
                if (frameworkElement != null)
                {
                    multiplier = itemsControl.Items.IndexOf(frameworkElement.DataContext);
                }
            }

            return(multiplier > -1 ? new TimeSpan(Unit.Ticks * multiplier) : TimeSpan.Zero);
        }