Example #1
0
        public static void SetScrollBarWidth(DependencyObject target, double width)
        {
            var thumb = VisualHelper.FindVisualChild <ScrollBar>(target, "VerticalScrollBar");

            if (thumb != null)
            {
                thumb.MaxWidth = thumb.MinWidth = width;
            }
        }
        private void ViewPage_Unloaded(object sender, RoutedEventArgs e)
        {
            var sd = sender as ListViewItem;

            if (sd != null)
            {
                var _t = VisualHelper.FindVisualChild(sd, "Gif_Image", typeof(ExToolKit.GIFImage)) as ExToolKit.GIFImage;
                //停止GIF播放并释放GIF图像资源
                if (_t != null)
                {
                    _t.ReleaseImages();
                }
            }
        }
Example #3
0
        private void DialogBase_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            var parent = VisualTreeHelper.GetParent(this);

            if (parent != null)
            {
                var rectangle = VisualHelper.FindVisualChild <Rectangle>(parent);
                if (rectangle != null)
                {
                    rectangle.Tapped += (s, a) => { Hide(); };
                }
            }
            Load();
        }
Example #4
0
        public void FindVisualChildTest()
        {
            var cnt = new ContentControl();
            var btn = new Button();

            //btn.Tag = "MyTag";
            btn.Name    = "MyTag";
            cnt.Content = btn;
            cnt.Focus();

            Visual           myVisual          = btn;
            string           tagOrNameToSearch = "MyTag";
            FrameworkElement expected          = btn; // TODO: Initialize to an appropriate value
            FrameworkElement actual;

            actual = VisualHelper.FindVisualChild(myVisual, tagOrNameToSearch);
            Assert.AreEqual(expected, actual);
        }
        private void NavigationPanel_Loaded(object sender, RoutedEventArgs e)
        {
            mHeaderList = VisualHelper.FindVisualChildrenEx <AduGroupBoxNor>(this.PART_ContentPresenter);
            if (mHeaderList != null)
            {
                List <object> list = new List <object>();
                mHeaderList.ForEach(p => list.Add(p));
                this.ItemsSource = list;
            }
            this.mScrollViewer = VisualHelper.FindVisualChild <ScrollViewer>(this.PART_ContentPresenter);
            if (this.mScrollViewer != null)
            {
                this.mScrollViewer.ScrollChanged += MScrollViewer_ScrollChanged;
            }

            object item = this.mHeaderList[this.IndicatorSelectedIndex];

            this.ScrollToSelection(item);
        }
Example #6
0
 public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 {
     if (value == null || !(value is TreeViewItem))
     {
         return(new System.Windows.Thickness(0, 0, 0, 0));
     }
     else
     {
         var P = VisualHelper.FindVisualParent((TreeViewItem)value, null, typeof(TreeViewItem));
         if (P != null)
         {
             var C = VisualHelper.FindVisualChild(P, "Head_Grid", typeof(Grid)) as Grid;
             if (C != null)
             {
                 return(new Thickness(C.Margin.Left + 10, 0, 0, 0));
             }
         }
     }
     return(new System.Windows.Thickness(0, 0, 0, 0));
 }
Example #7
0
        private void TabDrop(DropEventArgs e)
        {
            foreach (var item in tabs)
            {
                ListBoxItem      myListBoxItem      = (ListBoxItem)(TabsList.ItemContainerGenerator.ContainerFromItem(item));
                ContentPresenter myContentPresenter = VisualHelper.FindVisualChild <ContentPresenter>(myListBoxItem);

                if (myContentPresenter.IsMouseOver)
                {
                    var tabPosition = myContentPresenter.TransformToAncestor(FindMyWindow())
                                      .Transform(new Point(0, 0));

                    var position = new Point(e.RelativeMousePosition.X - tabPosition.X, e.RelativeMousePosition.Y - tabPosition.Y);

                    TabDropOnElement(item, position, e.Data as Model.UI.TabItem);
                    return;
                }
            }

            TabDropOnEmptyArea(e.Data as Model.UI.TabItem);
        }
Example #8
0
        private static void OnIsClippedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var  beh  = (MoveToViewboxBehavior)sender;
            Grid grid = beh.AssociatedObject;

            Viewbox          vb = VisualHelper.FindVisualChild <Viewbox>(grid);
            ContentPresenter cp = VisualHelper.FindVisualChild <ContentPresenter>(grid);

            if ((bool)e.NewValue)
            {
                // is clipped, so move content to Viewbox
                UIElement element = cp.Content as UIElement;
                cp.Content = null;
                vb.Child   = element;
            }
            else
            {
                // can be shown without clipping, so move content to ContentPresenter
                cp.Content = vb.Child;
                vb.Child   = null;
            }
        }
        /// <summary>
        /// 平滑滚动至指定元素
        /// </summary>
        /// <param name="itemsControl"></param>
        /// <param name="item"></param>
        public static void AnimateScrollIntoView(this ItemsControl itemsControl, object item)
        {
            ScrollViewer scrollViewer = VisualHelper.FindVisualChild <ScrollViewer>(itemsControl);

            if (scrollViewer == null)
            {
                return;
            }

            UIElement container = itemsControl.ItemContainerGenerator.ContainerFromItem(item) as UIElement;

            if (container == null)
            {
                return;
            }

            int index = itemsControl.ItemContainerGenerator.IndexFromContainer(container);

            //平滑滚动到元素所在位置
            //double toValue = scrollViewer.ScrollableHeight * ((double)index / itemsControl.Items.Count);
            //平滑滚动,将选中的元素置顶
            double toValue = VisualTreeHelper.GetOffset(container).Y;

            DoubleAnimation verticalAnimation = new DoubleAnimation();

            verticalAnimation.From = scrollViewer.VerticalOffset;
            verticalAnimation.To   = toValue;
            verticalAnimation.DecelerationRatio = .2;
            verticalAnimation.Duration          = new Duration(TimeSpan.FromMilliseconds(200));
            Storyboard storyboard = new Storyboard();

            storyboard.Children.Add(verticalAnimation);
            Storyboard.SetTarget(verticalAnimation, scrollViewer);
            Storyboard.SetTargetProperty(verticalAnimation, new PropertyPath(ScrollViewerBehavior.VerticalOffsetProperty));
            storyboard.Begin();
        }
Example #10
0
 private void ProjectItemDetailsViewOnLoaded(object sender, RoutedEventArgs e)
 {
     _errorsGridScrollViewer = VisualHelper.FindVisualChild <ScrollViewer>(ErrorsGrid);
     Debug.Assert(_errorsGridScrollViewer != null);
 }