FrameworkElement.BringIntoView 方法

定義

在內含此項目的任何可捲動區域內,嘗試將此項目帶入檢視。

多載

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 嵌的邏輯來檢視。 事件 RequestBringIntoViewBringIntoView 方法都不會傳輸有關成功或失敗的任何資訊,但事件通常標示為成功時處理。 失敗的原因可能包含專案設定,例如 Visibility 以外的一些值 Visible

如果您使用未指定 targetRectangle 的簽章,則會顯示整個元素大小 (其 RenderSize) 。

藉由呼叫這個方法,您可能會在任何包含 元素的父可捲動區域上呼叫 MakeVisible 。 如果這個專案未包含在可捲動區域中,仍 RequestBringIntoView 會引發事件,但不會有任何作用,因為沒有任何事件接聽程式。

另請參閱

適用於

BringIntoView()

在內含此項目的任何可捲動區域內,嘗試將此項目帶入檢視。

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

範例

下列範例會實作應用程式導覽事件的處理常式,每當巡覽至包含片段時,就會回應統一資源識別項 (URI) 。 片段會在雜湊符號 (#) 之後的 URI 中命名,而實作的行為會導致元素捲動到框架內的檢視中。 BringIntoViewRequestBringIntoView 要求範例中的捲動行為。

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 嵌的邏輯來檢視。 事件 RequestBringIntoViewBringIntoView 方法都不會傳輸有關成功或失敗的任何資訊,但事件通常標示為成功時處理。 失敗的原因可能包含專案設定,例如 Visibility 以外的一些值 Visible

如果您使用未指定 targetRectangle 的簽章,則會顯示整個元素大小 (其 RenderSize) 。

藉由呼叫這個方法,您可能會在任何包含 元素的父可捲動區域上呼叫 MakeVisible 。 如果這個專案未包含在可捲動區域中,仍 RequestBringIntoView 會引發事件,但不會有任何作用,因為沒有任何事件接聽程式。

另請參閱

適用於