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 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); }
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); }
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 は勝手に動く }
private void SfDataGrid_PreviewMouseWheel_ScrollViewer1(object sender, MouseWheelEventArgs e) { ScrollViewer1.ScrollToVerticalOffset(ScrollViewer1.VerticalOffset - e.Delta); }
private void ScrollViewer2_OnScrollChanged(object sender, ScrollChangedEventArgs e) { ScrollViewer1.ScrollToVerticalOffset(ScrollViewer2.VerticalOffset); }
private void DataGridCompetition_OnPreviewMouseWheel(object sender, MouseWheelEventArgs e) { ScrollViewer1.ScrollToVerticalOffset(ScrollViewer1.VerticalOffset - e.Delta); }