Dears,
Is there any event handler for the pivotgrid scroll?
Thanks,
Hi
There is not scroll event but you can find the scroll bar from control and to listen for thier scroll event. Below is a snippet how to find the scroll bar. The names of the bars you can see from generic.xaml from pivotgrid control template.
void PivotGridContainer_Loaded(object sender, RoutedEventArgs e) { ScrollBar vert = GetObject(PGrid, "VerticalScrollBar") as ScrollBar; ScrollBar horiz = GetObject(PGrid, "HorizontalScrollBar") as ScrollBar; } private DependencyObject GetObject(DependencyObject obj, string name) { DependencyObject child = null; int coutn = VisualTreeHelper.GetChildrenCount(obj); for (int index = 0; index < coutn; index++) { child = VisualTreeHelper.GetChild(obj, index); if (child is FrameworkElement && (child as FrameworkElement).Name == name) { return child; } child = GetObject(child, name); if (child != null) { return child; } } return child; }
ScrollBar vert = GetObject(PGrid, "VerticalScrollBar") as ScrollBar; ScrollBar horiz = GetObject(PGrid, "HorizontalScrollBar") as ScrollBar;
Todor
Hi,
after capturing the scroll of the grid, i want to scroll it to certain point
ScrollBar horiz = GetObject(pivotGrid, "HorizontalScrollBar") as ScrollBar; if (horiz != null) { horiz.Minimum = e.NewRect.X; horiz.Maximum = e.NewRect.X + e.NewRect.Width; }how to regive the grid the new scroll, or attache the grid to this scroll??
use horiz.Value=xxx'
hi
I am trying to bind the scroll of the datachart with the scroll of the grid
private void OnXamDataChartWindowRectChanged(object sender, RectChangedEventArgs e) { if (IsZoombarChanging) return; try { IsZoombarChanging = true; Range newZoombarRange = new Range { Minimum = e.NewRect.X, Maximum = e.NewRect.X + e.NewRect.Width }; if (this.xmZoombar != null) { this.xmZoombar.Range = newZoombarRange; } // this.pivotGrid.ScrollCellIntoView(this.pivotGrid.DataRows[0].Cells[size(newZoombarRange.Maximum)-1]); ScrollBar horiz = GetObject(pivotGrid, "HorizontalScrollBar") as ScrollBar; if (horiz != null) { horiz.Value = size(newZoombarRange.Maximum); } } finally { IsZoombarChanging = false; } }
when i am using the ScrollCellIntoView , it working, but when using the horiz.value its not.
i want also to capture the horizontal scroll value of the grid, so that when i scroll the grid, i would be able to scroll the chart too.
Because the thread become too overhead for tracking, please close this thread and post your question about chart scrolling in another thread according the datachart section
Regards
now i made a converter
Grid grid = GetObject(pivotGrid, "GridControlLayout") as Grid; ScrollBar scroll = grid.Children[2] as ScrollBar; // scroll.Value = size(this.xmZoombar.Range.Minimum); Binding binding = new Binding { Source = this.DataChart, Path = new PropertyPath("HorizontalZoombar.Range.Minimum"), Mode = BindingMode.TwoWay, Converter = new Converter2() }; scroll.SetBinding(ScrollBar.ValueProperty, binding);
public class Converter2 : IValueConverter { #region IValueConverter Members public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { // PivotRowHeaderCellControl cellControl = value as PivotRowHeaderCellControl; // PivotRowHeaderCell cell = cellControl.Cell as PivotRowHeaderCell; double test = 0; if (value != null) { test = Math.Round((double)value* 84); } return (int)(test); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return (double)value/84; } #endregion }
when i scroll the chart, the grid scroll too and its correct, but when i scroll the grid, nothing happen on the chart.
your help is appreciated
Thanks
I was able to write this
Grid grid = GetObject(pivotGrid, "GridControlLayout") as Grid; ScrollBar scroll = grid.Children[2] as ScrollBar; Binding binding = new Binding { Source = this.DataChart, Path = new PropertyPath("HorizontalZoombar.Range.Minimum"), Mode = BindingMode.TwoWay }; scroll.SetBinding(ScrollBar.ValueProperty, binding);
but the "HorizontalZoombar.Range.Minimum" does not return the index
i have to call the function:
private int size(double min) { double test = Math.Round(min * 84); return (int)(test); }
meaning the index of the columns equals to size(HorizontalZoombar.Range.Minimum),
how can i do that?
ok thanks it worked,
but how can i capture the scroll event, meaning when i scroll the grid, i want to take the value of this scroll
pivotgrid onscroll, is there is something like that?
Because there is a lot of elements in pivotGrid UI tree which are called "HorizontalScrollBar", and the frist one that method finds is not the decired one you can use this code to get the scroll bar:
Grid grid = GetObjectUI(pivotGrid, "GridControlLayout") as Grid; scroll = grid.Children[2] as ScrollBar;
Also the value of this scroll bar is the index of column which is first visible at the moment. This means that you should match your point to column index. For example if you have 30 columns and you want to scroll to point 100,100. you should match this point to column index 15 for example and then set scroll.Value=15.