語言

FrameworkElement.BringIntoView 方法

定義

嘗試將此元素帶入可捲動區域內的視覺化。

多載

名稱 Description
BringIntoView(Rect)

嘗試在任何可捲動的區域內,將該元素的區域大小顯示在視野中。

BringIntoView()

嘗試將此元素帶入可捲動區域內的視覺化。

BringIntoView(Rect)

嘗試在任何可捲動的區域內,將該元素的區域大小顯示在視野中。

public:
 void BringIntoView(System::Windows::Rect targetRectangle);
public void BringIntoView(System.Windows.Rect targetRectangle);
member this.BringIntoView : System.Windows.Rect -> unit
Public Sub BringIntoView (targetRectangle As Rect)

參數

targetRectangle
Rect

指定元素的大小,也應該被納入視野。

範例

以下範例在受限滾動區域內有一個大型圖形。 頁面上的一個按鈕有處理器,可以將視圖捲動到大型圖形的特定區域。

<ScrollViewer Width="300" Height="300" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible">
  <Image Name="mapframe" ScrollViewer.CanContentScroll="True"  >
    <Image.Source>
      <BitmapImage UriSource="treasuremap.bmp"/>
    </Image.Source>
  </Image>
</ScrollViewer>
<StackPanel>
  <Button Click="GoToLake">Go to Lake</Button>

</StackPanel>
void GoToLake(object sender, RoutedEventArgs e)
{
    mapframe.BringIntoView(new Rect(800, 400, 200, 200));
}
Private Sub GoToLake(ByVal sender As Object, ByVal e As RoutedEventArgs)
    mapframe.BringIntoView(New Rect(800, 400, 200, 200))
End Sub

備註

透過呼叫此方法,你會觸發 RequestBringIntoView 一個源自當前元素的事件。 此事件被提出,以便由 ScrollViewer、 或衍生類或類似類別處理。 預期的行為是事件由父元素處理,該元素在事件資料中標記為已處理,事件的來源則透過控制項中嵌入 ScrollViewer 的邏輯顯示出來。 事件與RequestBringIntoView方法均不BringIntoView傳送成功或失敗的任何資訊,僅表示事件通常標記為成功處理。 失敗的原因可能包括元素設定,例如 Visibility 是某個非 Visible的值。

如果你使用不指定 a targetRectangle的簽名,那麼整個元素大小(其 RenderSize)就會被顯示出來。

透過呼叫這個方法,你可能會呼叫 MakeVisible 包含該元素的任何父可滾動區域。 如果這個元素不包含在可捲動的區域內,事件 RequestBringIntoView 仍然會被提出,但不會有影響,因為沒有事件監聽器。

另請參閱

適用於

BringIntoView()

嘗試將此元素帶入可捲動區域內的視覺化。

public:
 void BringIntoView();
public void BringIntoView();
member this.BringIntoView : unit -> unit
Public Sub BringIntoView ()

範例

以下範例實作了一個用於應用程式導航事件的處理器,當所瀏覽的統一資源識別碼(URI)包含片段時,該處理程序會回應。 片段會在 URI 中命名,緊接雜湊符號(#),實作後的行為會使元素在畫面中捲入畫面。 BringIntoView 並 RequestBringIntoView 請求範例中的捲動行為。

void browserFrame_FragmentNavigation(object sender, FragmentNavigationEventArgs e)
{
    object content = ((ContentControl)e.Navigator).Content;
    FrameworkElement fragmentElement = LogicalTreeHelper.FindLogicalNode((DependencyObject)content, e.Fragment) as FrameworkElement;
    if (fragmentElement == null)
    {
        // Redirect to error page
        // Note - You can't navigate from within a FragmentNavigation event handler,
        //        hence creation of an async dispatcher work item
        this.Dispatcher.BeginInvoke(
            DispatcherPriority.Send,
            (DispatcherOperationCallback) delegate(object unused) 
            {
                this.browserFrame.Navigate(new Uri("FragmentNotFoundPage.xaml", UriKind.Relative));
                return null;
            },
            null);
        e.Handled = true;
    }
}
Private Sub browserFrame_FragmentNavigation(ByVal sender As Object, ByVal e As FragmentNavigationEventArgs)
    Dim element As FrameworkElement = TryCast(LogicalTreeHelper.FindLogicalNode(DirectCast(DirectCast(e.Navigator, ContentControl).Content, DependencyObject), e.Fragment), FrameworkElement)
    If (element Is Nothing) Then
        ' Redirect to error page
        ' Note - You can't navigate from within a FragmentNavigation event handler,
        '        hence creation of an async dispatcher work item
        Dim callback As New DispatcherOperationCallback(AddressOf Me.FragmentNotFoundNavigationRedirect)
        Me.Dispatcher.BeginInvoke(DispatcherPriority.Normal, callback, Nothing)
    End If
    e.Handled = True
End Sub

Function FragmentNotFoundNavigationRedirect(ByVal unused As Object) As Object
    Me.browserFrame.Navigate(New Uri("FragmentNotFoundPage.xaml", UriKind.Relative))
    Return Nothing
End Function

備註

透過呼叫此方法,你會觸發 RequestBringIntoView 一個源自當前元素的事件。 此事件被提出,以便由 ScrollViewer、 或衍生類或類似類別處理。 預期的行為是事件由父元素處理,該元素在事件資料中標記為已處理,事件的來源則透過控制項中嵌入 ScrollViewer 的邏輯顯示出來。 事件與RequestBringIntoView方法均不BringIntoView傳送成功或失敗的任何資訊,僅表示事件通常標記為成功處理。 失敗的原因可能包括元素設定,例如 Visibility 是某個非 Visible的值。

如果你使用不指定 a targetRectangle的簽名,那麼整個元素大小(其 RenderSize)就會被顯示出來。

透過呼叫這個方法,你可能會呼叫 MakeVisible 包含該元素的任何父可滾動區域。 如果這個元素不包含在可捲動的區域內,事件 RequestBringIntoView 仍然會被提出,但不會有影響,因為沒有事件監聽器。

另請參閱

適用於