public void Load(IPdfSource source, string password = null) { this.scrollViewer = this.ChildOfType <ScrollViewer>(); this.imageProvider = new PdfImageProvider(source, this.parent.TotalPages, new PageDisplaySettings(this.parent.GetPagesPerRow(), this.parent.ViewType, this.parent.HorizontalMargin, this.parent.Rotation), false, password); if (scrollViewer != null) { scrollViewer.RemoveHandler(UIElement.MouseWheelEvent, new MouseWheelEventHandler(this.OnScrollWheel)); scrollViewer.AddHandler(UIElement.MouseWheelEvent, new MouseWheelEventHandler(this.OnScrollWheel), true); } this.CurrentPageIndex = 0; if (this.scrollViewer != null) { this.scrollViewer.Visibility = System.Windows.Visibility.Visible; } if (this.parent.ZoomType == ZoomType.Fixed) { this.SetItemsSource(); } else if (this.parent.ZoomType == ZoomType.FitToHeight) { this.ZoomToHeight(); } else if (this.parent.ZoomType == ZoomType.FitToWidth) { this.ZoomToWidth(); } }
private void OnManipulationStarted(object sender, ManipulationStartedEventArgs e) { if (_scrollViewer.VerticalOffset <= 0.0) { _setup = true; _scrollViewer.AddHandler(ManipulationDeltaEvent, new EventHandler <ManipulationDeltaEventArgs>( OnManipulationDelta), true); _scrollViewer.ManipulationCompleted += OnManipulationCompleted; } }
private void ScrollViewerLoadedHandler(object sender, RoutedEventArgs e) { _scrollViewer = (ScrollViewer)sender; _scrollViewer.ViewChanged += ViewChangedHandler; _scrollViewer.AddHandler(PointerPressedEvent, new PointerEventHandler(PageViewControl_OnPointerPressed), true); var zoomInButton = (Button)_scrollViewer.FindDescendantByName("zoomInButton"); var zoomOutButton = (Button)_scrollViewer.FindDescendantByName("zoomOutButton"); var zoomControlsContainer = (Panel)_scrollViewer.FindDescendantByName("zoomControlsContainer"); if (new MouseCapabilities().MousePresent == 0) { zoomControlsContainer.Visibility = Visibility.Collapsed; } zoomInButton.Click += ZoomInButtonClickHandler; zoomOutButton.Click += ZoomOutButtonClickHandler; }
/// <summary> /// Invoked whenever application code or internal processes (such as a rebuilding /// layout pass) call <see cref="OnApplyTemplate"/>. In simplest terms, this means the method /// is called just before a UI element displays in an application. Override this /// method to influence the default post-template logic of a class. /// </summary> protected override void OnApplyTemplate() { m_root = this.GetTemplateChild(PART_ROOT) as UIElement; m_scroller = this.GetTemplateChild(PART_SCROLLER) as ScrollViewer; m_scrollerContent = this.GetTemplateChild(PART_SCROLLER_CONTENT) as UIElement; m_refreshIndicatorContainer = this.GetTemplateChild(PART_REFRESH_INDICATOR) as FrameworkElement; m_defaultRefreshIndicatorTextBlock = this.GetTemplateChild(PART_DEFAULT_REFRESH_INDICATOR_CONTENT) as TextBlock; if (m_root != null && m_scroller != null && m_scrollerContent != null && m_refreshIndicatorContainer != null) { m_scroller.DirectManipulationStarted += Scroller_DirectManipulationStarted; m_scroller.DirectManipulationCompleted += Scroller_DirectManipulationCompleted; m_scroller.ViewChanged += Scroller_ViewChanged; m_scroller.AddHandler(UIElement.PointerPressedEvent, new PointerEventHandler(Scroller_PointerPressed), true); // In AutoRefresh mode, zoom factors smaller or larger than 1.0 are not supported. if (this.AutoRefresh) { m_scroller.MinZoomFactor = 1.0f; m_scroller.MaxZoomFactor = 1.0f; m_scroller.ZoomMode = ZoomMode.Disabled; } m_refreshIndicatorContainer.SizeChanged += RefreshIndicatorContainer_SizeChanged; } if (m_defaultRefreshIndicatorTextBlock != null) { m_defaultRefreshIndicatorTextBlock.Visibility = this.RefreshIndicatorContent == null ? Visibility.Visible : Visibility.Collapsed; } base.OnApplyTemplate(); }
public MainWindow() { InitializeComponent(); Random rand = new Random(); StackPanel sp = new StackPanel(); for (int i = 0; i < 20; i++) { Button btn = new Button(); btn.HorizontalAlignment = HorizontalAlignment.Center; btn.Margin = new Thickness(5); btn.FontSize += rand.Next(10); btn.Name = ((char)('A' + i)).ToString(); btn.Content = $"Button {btn.Name} says 'Click me'"; //btn.Click += Btn_Click; sp.Children.Add(btn); } sp.HorizontalAlignment = HorizontalAlignment.Center; //sp.AddHandler(Button.ClickEvent, new RoutedEventHandler(Btn_Click)); ScrollViewer scroll = new ScrollViewer(); scroll.Content = sp; scroll.AddHandler(Button.ClickEvent, new RoutedEventHandler(Btn_Click)); this.MaxHeight = 500; this.SizeToContent = SizeToContent.WidthAndHeight; this.ResizeMode = ResizeMode.CanMinimize; this.Content = scroll; //sp.Children[5] //sp.Children.IndexOf(btnC) }