/******************************/ /* Other Functions */ /******************************/ #region Other Functions /// <summary> /// AddMessage /// </summary> /// <param name="message"></param> /// <param name="direction"></param> public void AddMessage(byte[] message, Direction direction) { LineStackPanel.Children.Add(new HexMessageUC { HexContentByte = message, MessageDirection = direction }); ScrollViewer1.ScrollToBottom(); }
private void ScrollViewer(object sender, RoutedEventArgs e) { /* * UIElement.UpdateLayout * Ensures that all positions of child objects of * a UIElement are properly updated for layout. */ ScrollViewer1.UpdateLayout(); /* * ScrollViewer.ChangeView * Causes the ScrollViewer to load a new view into * the viewport using the specified offsets and zoom factor. */ // Programmatically scroll to bottom ScrollViewer1.ChangeView( 0.0f, // horizontalOffset double.MaxValue, // verticalOffset 1.0f // zoomFactor ); // Another way to programmatically scroll to bottom // But above way is better //ScrollViewer1.ScrollToVerticalOffset(ScrollViewer1.ScrollableHeight); }
/// <summary> /// Событие на отпускание мышки на Stack Panel /// </summary> /// <param name="sender">StackPanel</param> /// <param name="e">MouseButtonEventArgs</param> private void StackPanelMouseUp(object sender, MouseButtonEventArgs e) { if (e.ChangedButton != MouseButton.Left) { return; } if (!_keyDown) { return; } _keyDown = false; if (ScrollViewer1.ScrollableWidth - _size.Width / 2 >= ScrollViewer1.HorizontalOffset && _size.Width / 2 <= ScrollViewer1.HorizontalOffset) { ScrollViewer1.ScrollToHorizontalOffset(_size.Width); return; } if (_size.Width / 2 > ScrollViewer1.HorizontalOffset) { ScrollViewer1.ScrollToHorizontalOffset(0); AddAndRemoveImage(ScrollViewer1); } else { ScrollViewer1.ScrollToHorizontalOffset(ScrollViewer1.ScrollableWidth); AddAndRemoveImage(ScrollViewer1); } }
void NavigateToPage(string targetUri) { //Hide the menu: if (_currentState == CurrentState.SmallResolution_ShowMenu) { GoToState(CurrentState.SmallResolution_HideMenu); } // Display the "Loading..." text: LoadingMessage.Visibility = Visibility.Visible; // We use the Dispatcher to give enough time to the browser to refresh and show the "Loading..." text: Dispatcher.BeginInvoke((Action)(() => { // Navigate to the target page: Uri uri = new Uri(targetUri, UriKind.Relative); PageContainer.Source = uri; // Scroll to top: ScrollViewer1.ScrollToVerticalOffset(0d); // Hide the "Loading..." text: LoadingMessage.Visibility = Visibility.Collapsed; })); }
public void ScrollToUiElement(UIElement element) { UIElement containerElement = VisualTreeHelper.GetParent(element) as UIElement; Point relativeLocation = element.TranslatePoint(new Point(0, 0), containerElement); ScrollViewer1.ScrollToVerticalOffset(relativeLocation.Y); }
public MainWindow() { //// コードからリソースディクショナリーファイルを読み込む方法 //// 一般的にはこのようなコードを書く。 //// ※URIの書き方は、次を参照 //// https://docs.microsoft.com/ja-jp/dotnet/framework/wpf/app-development/pack-uris-in-wpf?redirectedfrom=MSDN#resource-file-pack-uris //// ※ここで App のリソースを ResourceDictionary1.xaml だけに置き換えるので、 //// 実行すると ResourceDictionary1.xaml のリソースだけが適用される。 //Uri resourceLocater = new Uri("pack://application:,,,/ResourceDictionary1.xaml"); //// ↑↓どちらで書いてもよい Uri resourceLocater = new Uri("/ResourceDictionary1.xaml", UriKind.Relative); var resource1 = new ResourceDictionary() { Source = resourceLocater }; App.Current.Resources = resource1; //// リソースディクショナリーファイルに細工をしておくと、new できる //// ※ここで App のリソースを置き換えるので、実行すると //// ResourceDictionary2.xaml がプライマリーディクショナリーになり、 //// ResourceDictionary1.xaml がマージドディクショナリーに入る。 //// (Brush1 リソースの定義は ResourceDictionary1.xaml だけにある) //var resource2 = new ResourceDictionary2(); //App.Current.Resources = resource2; //App.Current.Resources.MergedDictionaries.Add(resource1); InitializeComponent(); // 一番下までスクロールさせる ScrollViewer1.ScrollToVerticalOffset(double.MaxValue); }
private void UIElement_OnPreviewMouseWheel1(object sender, MouseWheelEventArgs e) { var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta); eventArg.RoutedEvent = UIElement.MouseWheelEvent; eventArg.Source = sender; ScrollViewer1.RaiseEvent(eventArg); }
private void NavigateToPage(string pageName) { // Navigate to the target page: Uri uri = new Uri($"/{pageName}Test", UriKind.Relative); ContentContainer.Source = uri; // Scroll to top: ScrollViewer1.ScrollToVerticalOffset(0d); }
private void sv2_ScrollChanged(object sender, ScrollChangedEventArgs e) { ScrollViewer sv = e.OriginalSource as ScrollViewer; if (sv != null) { ScrollViewer1.ScrollToHorizontalOffset(sv.HorizontalOffset); ScrollViewer3.ScrollToVerticalOffset(sv.VerticalOffset); } }
public void CompleteStep2() { Expander_Step2.IsEnabled = false; Expander_Step2.IsExpanded = false; Expander_Step3.Visibility = UIConstants.VISIBILITY_VISIBLE; Expander_Step3.IsEnabled = true; Expander_Step3.IsExpanded = true; ScrollViewer1.ScrollToTop(); }
private void ListBox1_PreviewMouseWheel(object sender, MouseWheelEventArgs e) { if (e.Delta < 0) { ScrollViewer1.LineDown(); } else { ScrollViewer1.LineUp(); } }
public void NavigateToPage(string targetUri) { //Hide the menu: if (_currentState == CurrentState.SmallResolution_ShowMenu) { GoToState(CurrentState.SmallResolution_HideMenu); } // Navigate to the target page: Uri uri = new Uri(targetUri, UriKind.Relative); PageContainer.Source = uri; // Scroll to top: ScrollViewer1.ScrollToVerticalOffset(0d); }
/// <summary> /// ProcessMessage /// </summary> /// <param name="message"></param> /// <param name="direction"></param> private void ProcessMessage(byte[] message, Direction direction) { if (DispatcherObjectMessage.Thread != System.Threading.Thread.CurrentThread) { DispatcherObjectMessage.Invoke(new ProcessMessageDelegate(ProcessMessage), System.Windows.Threading.DispatcherPriority.ApplicationIdle, message, direction); } else { try { LineStackPanel.Children.Add(new HexMessageUC { HexContentByte = message, MessageDirection = direction }); ScrollViewer1.ScrollToBottom(); } catch (Exception ex) { _logger.Error("Exception in ProcessMessage " + ex.Message); } } }
/// <summary> /// Событие на нажатие клавиш на клавиатуре /// </summary> /// <remarks>обрабатывает : вправо, влево, выход и автопроигрывание</remarks> /// <param name="sender">ScrollViewer</param> /// <param name="e">KeyEventArgs</param> private void ScrollViewerKeyDown(object sender, KeyEventArgs e) { switch (e.Key) { case Key.Right: ScrollViewer1.ScrollToRightEnd(); break; case Key.Left: ScrollViewer1.ScrollToLeftEnd(); break; case Key.Enter: case Key.Escape: OnOnStop(new EventArgs()); Close(); break; case Key.Space: break; } }
private void SearchButton_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(SearchTextBox.Text)) { return; } var search = SearchTextBox.Text; if (search != currentSearch) { searchIndex = 0; currentSearchResult = null; currentSearch = search; } if (currentSearchResult == null) { currentSearchResult = _hexLabels.FindAll(label => ((string)label.Content).Contains(search)); if (currentSearchResult.Count == 0) { MessageBox.Show("見つかりませんでした。"); currentSearchResult = null; return; } } if (searchIndex != 0 && searchIndex % currentSearchResult.Count == 0) { MessageBox.Show("先頭に戻りました"); } var selection = currentSearchResult[searchIndex++ % currentSearchResult.Count]; SelectLabel(selection); ScrollViewer1.ScrollToVerticalOffset(selection.Margin.Top); // 2 は勝手に動く }
public void Log(string msg) { textBlock1.Dispatcher.Invoke(new Action(() => { textBlock1.Text += Time() + msg + "\n";; })); ScrollViewer1.Dispatcher.Invoke(new Action(() => { ScrollViewer1.ScrollToEnd(); })); }
private void SfDataGrid_PreviewMouseWheel_ScrollViewer1(object sender, MouseWheelEventArgs e) { ScrollViewer1.ScrollToVerticalOffset(ScrollViewer1.VerticalOffset - e.Delta); }
private void DataGridCompetition_OnPreviewMouseWheel(object sender, MouseWheelEventArgs e) { ScrollViewer1.ScrollToVerticalOffset(ScrollViewer1.VerticalOffset - e.Delta); }
private void ScrollChanged(object sender, ScrollChangedEventArgs e) { ScrollViewer1.ScrollToHorizontalOffset(e.HorizontalOffset); }
private void TextBox1_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e) { // 在此处添加事件处理程序实现。 ScrollViewer1.ScrollToEnd(); }
private void log(string msg) { textBlock1.Dispatcher.Invoke(new Action(() => { textBlock1.Text += GetTimeNow() + msg + "\n";; })); ScrollViewer1.Dispatcher.Invoke(new Action(() => { ScrollViewer1.ScrollToEnd(); })); }
private void ScrollViewer2_OnScrollChanged(object sender, ScrollChangedEventArgs e) { ScrollViewer1.ScrollToVerticalOffset(ScrollViewer2.VerticalOffset); }