Exemplo n.º 1
0
        public virtual void ScrollIntoViewTooLarge()
        {
            Button a = new Button
            {
                Content             = "a",
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top
            };
            Button b = new Button
            {
                Content             = "b",
                HorizontalAlignment = HorizontalAlignment.Right,
                VerticalAlignment   = VerticalAlignment.Bottom
            };
            Grid grid = new Grid {
                Width = 200, Height = 200
            };

            grid.Children.Add(a);
            grid.Children.Add(b);

            ScrollViewer viewer = CreateTestScrollViewer(grid, 150, 150);

            TestAsync(
                ScrollDelay,
                viewer,
                () => viewer.ScrollIntoView(grid),
                () => Assert.IsFalse(IsInView(viewer, grid), "Grid should not fit in the view!"),
                () => Assert.IsTrue(IsInView(viewer, a), "The a Button should be in view!"),
                () => Assert.IsFalse(IsInView(viewer, b), "The b Button should not fit in the view!"));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 展开车辆
        /// </summary>
        /// <param name="car"></param>
        public void ExpandCar(SLCar car)
        {
            if (_tvScrollViewer == null)
            {
                _tvScrollViewer = tv.GetScrollHost();
            }
            SLTreeView2Data data = _rootUnitData.GetTreeViewDataByCar(car);

            if (data != null)
            {
                var datas = data.GetTreeViewDataParents(false);
                if (datas.Any())
                {
                    tv.ExpandPath(datas);
                }

                tv.SelectItem(data);
                if (tv.SelectedItem == null || tv.SelectedItem != data)
                {
                    DispatcherTimer timer = new DispatcherTimer();
                    timer.Tick += (sender, args) =>
                    {
                        if (tv.SelectedItem != null && tv.SelectedItem == data)
                        {
                            _tvScrollViewer.ScrollIntoView(tv.GetSelectedContainer());
                            timer.Stop();
                            timer = null;
                        }
                        else
                        {
                            tv.SelectItem(data);
                        }
                    };
                    timer.Interval = new TimeSpan(0, 0, 0, 0, 300);
                    timer.Start();
                }
                else
                {
                    _tvScrollViewer.ScrollIntoView(tv.GetSelectedContainer());
                }
            }
        }
Exemplo n.º 3
0
        public virtual void ScrollIntoViewNotInVisualTree()
        {
            Button button = new Button {
                Content = "Test"
            };
            ScrollViewer viewer = CreateTestScrollViewer(button, 200, 200);

            viewer.ScrollIntoView(button);
            Assert.AreEqual(0, viewer.VerticalOffset, "Should not have not scroll vertically!");
            Assert.AreEqual(0, viewer.HorizontalOffset, "Should not have not scroll horizontally!");
        }
Exemplo n.º 4
0
        private void InsertItem(int index, object item)
        {
            var children = this.tagPanel.Children;

            var resolvedTag = new ResolvedTag {
                DataContext = item
            };

            if (TagStyle != null)
            {
                resolvedTag.Style = TagStyle;
            }

            var resolvedTag2 = resolvedTag;

            resolvedTag2.ShowAddAnimation = true;

            InsertTag(index, resolvedTag2);

            if (index == 0)
            {
                InsertTag(index, NewUnresolved());
            }

            if (children.IndexOf(resolvedTag2) == children.Count - 1)
            {
                InsertTag(children.IndexOf(resolvedTag2) + 1, NewUnresolved());
            }

            if (!(children[children.IndexOf(resolvedTag2) - 1] is UnresolvedTag))
            {
                InsertTag(children.IndexOf(resolvedTag2), NewUnresolved());
            }

            if (!(children[children.IndexOf(resolvedTag2) + 1] is UnresolvedTag))
            {
                InsertTag(children.IndexOf(resolvedTag2) + 1, NewUnresolved());
            }

            var relativeIndex = GetRelativeIndex(resolvedTag2);

            EnableChangePropagation = false;

            if (!Propagating)
            {
                ItemsSource?.Insert(relativeIndex, item);
            }

            EnableChangePropagation = true;

            resolvedTag2.AddCompleted += delegate {
                tagScrollViewer.ScrollIntoView(resolvedTag);
            };
        }
 public static void ScrollIntoView(this ScrollViewer viewer, FrameworkElement element)
 {
     if (viewer == null)
     {
         throw new ArgumentNullException(nameof(viewer));
     }
     if (element == null)
     {
         throw new ArgumentNullException(nameof(element));
     }
     viewer.ScrollIntoView(element, 0.0, 0.0, TimeSpan.Zero);
 }
Exemplo n.º 6
0
        public virtual void ScrollIntoViewElementNotInVisualTree()
        {
            Button button = new Button {
                Content = "Test"
            };
            ScrollViewer viewer = CreateTestScrollViewer();

            TestAsync(
                ScrollDelay,
                viewer,
                () => viewer.ScrollIntoView(button),
                () => Assert.AreEqual(0, viewer.VerticalOffset, "Should not have not scroll vertically!"),
                () => Assert.AreEqual(0, viewer.HorizontalOffset, "Should not have not scroll horizontally!"));
        }
Exemplo n.º 7
0
        public virtual void ScrollIntoViewBasic()
        {
            Button button = new Button {
                Content = "Test"
            };
            ScrollViewer viewer = CreateTestScrollViewer(button, 200, 200);

            TestAsync(
                ScrollDelay,
                viewer,
                () => viewer.ScrollIntoView(button),
                () => Assert.AreNotEqual(0, viewer.VerticalOffset, "Should have scrolled vertically!"),
                () => Assert.AreNotEqual(0, viewer.HorizontalOffset, "Should have scrolled horizontally!"),
                () => Assert.IsTrue(IsInView(viewer, button), "Button should be in view!"));
        }
Exemplo n.º 8
0
        public virtual void ScrollIntoViewAlreadyInView()
        {
            Button button = new Button {
                Content = "Test"
            };
            ScrollViewer viewer = CreateTestScrollViewer(button, 105, 105);

            TestAsync(
                ScrollDelay,
                viewer,
                () => viewer.ScrollToVerticalOffset(100),
                () => viewer.ScrollToHorizontalOffset(100),
                () => Assert.IsTrue(IsInView(viewer, button), "Button should start in view!"),
                () => viewer.ScrollIntoView(button),
                () => Assert.IsTrue(IsInView(viewer, button), "Button is still in view!"),
                () => Assert.AreEqual(100, viewer.VerticalOffset, "Should not have scrolled vertically!"),
                () => Assert.AreEqual(100, viewer.HorizontalOffset, "Should not have scrolled horizontally!"));
        }
 public virtual void ScrollIntoViewRequiresElement()
 {
     ScrollViewer viewer = new ScrollViewer();
     viewer.ScrollIntoView(null);
 }
        /// <summary>
        /// building grid for the gadget
        /// </summary>
        /// <param name="e"></param>
        void DataContextSource_RelativePerformanceGridBuildEvent(RelativePerformanceGridBuildEventArgs e)
        {
            relativePerformanceSectorInfo = e.RelativePerformanceSectorInfo;

            //clear grid of previous sector info
            for (int columnIndex = 1; columnIndex < this.dgRelativePerformance.Columns.Count - 1;)
            {
                this.dgRelativePerformance.Columns.RemoveAt(columnIndex);
            }

            int cIndex = 0;

            foreach (RelativePerformanceSectorData sectorData in e.RelativePerformanceSectorInfo)
            {
                Telerik.Windows.Controls.GridViewDataColumn dataColumn = new Telerik.Windows.Controls.GridViewDataColumn();
                dataColumn.Header            = sectorData.SectorName;
                dataColumn.UniqueName        = sectorData.SectorName;
                dataColumn.DataMemberBinding = new System.Windows.Data.Binding("RelativePerformanceCountrySpecificInfo[" + cIndex + "]");

                StringBuilder CellTemp = new StringBuilder();
                CellTemp.Append("<DataTemplate");
                CellTemp.Append(" xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'");
                CellTemp.Append(" xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'");

                //Be sure to replace "YourNamespace" and "YourAssembly" with your app's
                //actual namespace and assembly here
                //      Changed the following block to use converter and publish in Basis Points
                CellTemp.Append(" xmlns:lanes='clr-namespace:GreenField.Gadgets.Helpers;assembly=GreenField.Gadgets'");
                CellTemp.Append(" xmlns:local='clr-namespace:GreenField.Gadgets.Views;assembly=GreenField.Gadgets'>");
                CellTemp.Append("<StackPanel Orientation='Horizontal'>");
                CellTemp.Append("<TextBlock>");
                CellTemp.Append("   <TextBlock.Text>");
                CellTemp.Append("       <Binding Path='RelativePerformanceCountrySpecificInfo[" + cIndex + "].Alpha'>");
                CellTemp.Append("           <Binding.Converter>");
                CellTemp.Append("               <lanes:BasisPointsConverter/>");
                CellTemp.Append("           </Binding.Converter>");
                CellTemp.Append("       </Binding>");
                CellTemp.Append("   </TextBlock.Text>");
                CellTemp.Append("</TextBlock>");
                CellTemp.Append("</StackPanel>");
                CellTemp.Append("</DataTemplate>");

                dataColumn.CellTemplate = XamlReader.Load(CellTemp.ToString()) as DataTemplate;

                decimal?aggregateSectorAlphaValue = e.RelativePerformanceInfo.Select(t => t.RelativePerformanceCountrySpecificInfo.ElementAt(cIndex))
                                                    .Sum(t => t.Alpha == null ? 0 : t.Alpha);
                string  aggregateSectorAlpha = aggregateSectorAlphaValue == null ? String.Empty : Decimal.Parse(aggregateSectorAlphaValue.ToString()).ToString();
                decimal?aggregateSectorActiviePositionValue = e.RelativePerformanceInfo.Select(t => t.RelativePerformanceCountrySpecificInfo.ElementAt(cIndex))
                                                              .Sum(t => t.ActivePosition == null ? 0 : t.ActivePosition);
                string aggregateSectorActiviePosition = aggregateSectorActiviePositionValue == null ? String.Empty
                                                                                         : (Decimal.Parse(aggregateSectorActiviePositionValue.ToString())).ToString();

                var aggregateAlphaSumFunction = new AggregateFunction <RelativePerformanceData, string>
                {
                    AggregationExpression = Models => aggregateSectorAlpha,
                    FunctionName          = sectorData.SectorId.ToString()
                };

                dataColumn.FooterTextAlignment = TextAlignment.Right;
                dataColumn.Width = GridViewLength.Auto;
                dataColumn.AggregateFunctions.Add(aggregateAlphaSumFunction);

                TextBlock spFunctions = new TextBlock()
                {
                    Text          = aggregateSectorActiviePosition.ToString(),
                    Tag           = sectorData.SectorId,
                    TextAlignment = TextAlignment.Right,
                    FontSize      = 9
                };

                TextBlock footerText = new TextBlock()
                {
                    Text          = (Convert.ToDecimal(aggregateSectorAlpha) * 10000).ToString("n0"), //Needs to be displayed in basis points
                    Tag           = sectorData.SectorId,
                    TextAlignment = TextAlignment.Right,
                    FontSize      = 9
                };

                ToolTipService.SetToolTip(footerText, spFunctions);
                dataColumn.Footer          = footerText;
                dataColumn.HeaderCellStyle = this.Resources["GridViewHeaderCellClickable"] as Style;
                dataColumn.FooterCellStyle = this.Resources["GridViewCustomFooterCellStyle"] as Style;
                dataColumn.CellStyle       = this.Resources["GridViewCellStyle"] as Style;
                dgRelativePerformance.Columns.Insert(++cIndex, dataColumn);
            }

            RelativePerformanceInfo = e.RelativePerformanceInfo;

            dbInteractivity = (this.DataContext as ViewModelRelativePerformance).dbInteractivity;
            eventAggregator = (this.DataContext as ViewModelRelativePerformance).eventAggregator;

            //design grid for sector specific top alpha security grid

            if (this.dpTopActivePositionSecurity.Children != null)
            {
                this.dpTopActivePositionSecurity.Children.Clear();
            }

            if (e.RelativePerformanceSectorInfo != null)
            {
                ScrollViewer svc = new ScrollViewer()
                {
                    HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                    VerticalScrollBarVisibility   = ScrollBarVisibility.Hidden
                };

                Grid grd = new Grid()
                {
                    ShowGridLines = false, UseLayoutRounding = true
                };
                grd.RowDefinitions.Add(new RowDefinition()
                {
                    Height = GridLength.Auto
                });
                grd.RowDefinitions.Add(new RowDefinition()
                {
                    Height = GridLength.Auto
                });
                grd.RowDefinitions.Add(new RowDefinition()
                {
                    Height = GridLength.Auto
                });
                grd.RowDefinitions.Add(new RowDefinition()
                {
                    Height = GridLength.Auto
                });

                int sectorNum = 0;

                for (int i = 0; i < e.RelativePerformanceSectorInfo.Count; i++)
                {
                    int securityNum = 1;

                    List <SecurityDetail> sectorSpecificTopAlphaSecurityNames = e.RelativePerformanceSecurityInfo
                                                                                .Where(record => record.SecuritySectorName == e.RelativePerformanceSectorInfo[i].SectorName)
                                                                                .OrderByDescending(record => record.SecurityAlpha)
                                                                                .Take(3)
                                                                                .Select(record => new SecurityDetail()
                    {
                        SecurityName  = record.SecurityName,
                        SecurityAlpha = record.SecurityAlpha == null
                                ? "Null" : String.Format("{0}", record.SecurityAlpha.Value)
                    })
                                                                                .ToList();

                    TextBox sectorHeader = new TextBox()
                    {
                        Text       = e.RelativePerformanceSectorInfo[i].SectorName,
                        FontWeight = FontWeights.Bold,
                        FontFamily = new FontFamily("Arial"),
                        IsReadOnly = true,
                        Background = new SolidColorBrush(Color.FromArgb(255, 203, 212, 241)),
                        Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0)),
                        FontSize   = 9,
                        Margin     = new Thickness(2)
                    };

                    grd.ColumnDefinitions.Add(new ColumnDefinition()
                    {
                        Width = GridLength.Auto
                    });
                    int colIndex = grd.ColumnDefinitions.Count() - 1;

                    sectorHeader.SetValue(Grid.RowProperty, 0);
                    sectorHeader.SetValue(Grid.ColumnProperty, colIndex);
                    grd.Children.Add(sectorHeader);

                    foreach (SecurityDetail securityName in sectorSpecificTopAlphaSecurityNames)
                    {
                        TextBlock txtSecurityName = new TextBlock()
                        {
                            Text = securityName.SecurityName
                                   + " (" + (Convert.ToDecimal(securityName.SecurityAlpha) * 10000).ToString("n0") + ")", //Needs to be displayed in basis points
                            FontSize   = 9,
                            FontWeight = FontWeights.Normal,
                            FontFamily = new FontFamily("Arial"),
                            Margin     = new Thickness(2)
                        };
                        txtSecurityName.SetValue(Grid.ColumnProperty, sectorNum);
                        txtSecurityName.SetValue(Grid.RowProperty, securityNum);
                        grd.Children.Add(txtSecurityName);
                        securityNum++;
                    }
                    sectorNum++;
                }

                svc.ScrollIntoView(grd);
                svc.Content = grd;
                this.dpTopActivePositionSecurity.Children.Add(svc);
            }
        }
Exemplo n.º 11
0
        public virtual void ScrollIntoViewRequiresElement()
        {
            ScrollViewer viewer = new ScrollViewer();

            viewer.ScrollIntoView(null);
        }
Exemplo n.º 12
0
        public virtual void ScrollIntoViewRequiresViewer()
        {
            ScrollViewer viewer = null;

            viewer.ScrollIntoView(new Button());
        }