Ejemplo n.º 1
0
        private void focusOnElement(FrameworkElement element)
        {
            if (this.FindName(element.Name) != null)
            {
                object       parent    = element;
                ScrollViewer viewer    = null;
                Pivot        pivot     = Pivot;
                PivotItem    pivotItem = null;
                if (Pivot.FindName(element.Name) != null)
                {
                    foreach (object item in Pivot.Items)
                    {
                        if (item.GetType() == typeof(PivotItem))
                        {
                            if (((PivotItem)item).FindName(element.Name) != null)
                            {
                                pivotItem = (PivotItem)item;
                            }
                        }
                    }
                }
                if (pivotItem != null)
                {
                    Pivot.SelectedItem = pivotItem;
                }

                object Parent = element.Parent;
                while (Parent != null)
                {
                    if (Parent.GetType() == typeof(ScrollViewer))
                    {
                        viewer = (ScrollViewer)Parent;
                    }
                    Parent = ((FrameworkElement)Parent).Parent;
                }
                if (viewer != null)
                {
                    //var transform = element.TransformToVisual(Application.Current.RootVisual);
                    //Point offset = transform.Transform(new Point(0, 0));
                    //double height = Application.Current.RootVisual.RenderSize.Height;
                    //if (offset.Y > height)
                    //{
                    //    double center = height / 2;
                    //    double diff = offset.Y - center;
                    viewer.ScrollToVerticalOffset(viewer.VerticalOffset + 100);
                    //}
                }
            }
        }