FrameworkElement.BringIntoView FrameworkElement.BringIntoView FrameworkElement.BringIntoView FrameworkElement.BringIntoView Method

定義

在內含此項目的任何可捲動區域內,嘗試將此項目帶入檢視。Attempts to bring this element into view, within any scrollable regions it is contained within.

多載

BringIntoView(Rect) BringIntoView(Rect) BringIntoView(Rect) BringIntoView(Rect)

在內含此項目的任何可捲動區域內,嘗試將此項目所提供的區域大小帶入檢視。Attempts to bring the provided region size of this element into view, within any scrollable regions it is contained within.

BringIntoView() BringIntoView() BringIntoView() BringIntoView()

在內含此項目的任何可捲動區域內,嘗試將此項目帶入檢視。Attempts to bring this element into view, within any scrollable regions it is contained within.

BringIntoView(Rect) BringIntoView(Rect) BringIntoView(Rect) BringIntoView(Rect)

在內含此項目的任何可捲動區域內,嘗試將此項目所提供的區域大小帶入檢視。Attempts to bring the provided region size of this element into view, within any scrollable regions it is contained within.

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 Rect Rect Rect

指定同樣應帶入檢視的項目大小。Specified size of the element that should also be brought into view.

範例

下列範例在受限的捲動區域中有大型圖形。The following example has a large graphic in a constrained scrolling region. 頁面上的按鈕具有處理常式, 可將視圖滾動到大型圖形的特定區域。A button on the page has a handler that scrolls the view to a particular region of the large graphic.

<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引發源自目前元素的事件。By calling this method, you raise a RequestBringIntoView event that originates from the current element. 引發此事件的方式ScrollViewer, 是由或衍生或類似的類別來處理。This event is raised so that it can be handled by a ScrollViewer, or a derived or similar class. 預期的行為是由父元素處理事件, 並在事件資料中標示為已處理, 而事件的來源則會透過內嵌在ScrollViewer控制項中的邏輯帶入查看。The expected behavior is that the event is handled by the parent element, marked handled in the event data, and the source of the event is brought into view through the logic embedded in the ScrollViewer control. RequestBringIntoView 事件BringIntoView和方法都不會傳輸任何有關成功或失敗的資訊, 而是事件通常會標示為成功處理。Neither the RequestBringIntoView event nor the BringIntoView method transmit any information about success or failure, other than that the event is typically marked handled on success. 失敗的原因可能包括元素設定, 例如Visibility以外的某個值。 VisibleReasons for failure can include the element settings, such as Visibility being some value other than Visible.

如果您使用未指定targetRectangle的簽章, 則會顯示整個元素大小 (其RenderSize)。If you use the signature that does not specify a targetRectangle, then the entire element size (its RenderSize) will be made visible.

藉由呼叫這個方法, 您可能會MakeVisible在包含專案的任何父系可捲動區域上呼叫。By calling this method, you potentially will call MakeVisible on any parent scrollable area that contains the element. 如果這個專案不包含在可捲動區域中, RequestBringIntoView仍會引發事件, 但不會有任何作用, 因為沒有事件接聽程式。If this element is not contained in a scrollable area, the RequestBringIntoView event is still raised, but there will be no effect because there are no event listeners.

另請參閱

BringIntoView() BringIntoView() BringIntoView() BringIntoView()

在內含此項目的任何可捲動區域內,嘗試將此項目帶入檢視。Attempts to bring this element into view, within any scrollable regions it is contained within.

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

範例

下列範例會執行應用程式導覽事件的處理常式, 以在每統一資源識別項 (URI)uniform resource identifier (URI)次流覽時回應以包含片段。The following example implements a handler for an application navigation event that responds whenever the 統一資源識別項 (URI)uniform resource identifier (URI) being navigated to includes a fragment. 片段會在URIURI下列雜湊符號 (#) 中命名, 而實行為會導致元素在框架內的視圖中進行滾動。The fragment is named in the URIURI following the hash sign (#), and the implemented behavior causes the element to scroll into view within the frame. BringIntoViewRequestBringIntoView會要求該範例中的滾動行為。BringIntoView and RequestBringIntoView request that scrolling behavior in the example.

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引發源自目前元素的事件。By calling this method, you raise a RequestBringIntoView event that originates from the current element. 引發此事件的方式ScrollViewer, 是由或衍生或類似的類別來處理。This event is raised so that it can be handled by a ScrollViewer, or a derived or similar class. 預期的行為是由父元素處理事件, 並在事件資料中標示為已處理, 而事件的來源則會透過內嵌在ScrollViewer控制項中的邏輯帶入查看。The expected behavior is that the event is handled by the parent element, marked handled in the event data, and the source of the event is brought into view through the logic embedded in the ScrollViewer control. RequestBringIntoView 事件BringIntoView和方法都不會傳輸任何有關成功或失敗的資訊, 而是事件通常會標示為成功處理。Neither the RequestBringIntoView event nor the BringIntoView method transmit any information about success or failure, other than that the event is typically marked handled on success. 失敗的原因可能包括元素設定, 例如Visibility以外的某個值。 VisibleReasons for failure can include the element settings, such as Visibility being some value other than Visible.

如果您使用未指定targetRectangle的簽章, 則會顯示整個元素大小 (其RenderSize)。If you use the signature that does not specify a targetRectangle, then the entire element size (its RenderSize) will be made visible.

藉由呼叫這個方法, 您可能會MakeVisible在包含專案的任何父系可捲動區域上呼叫。By calling this method, you potentially will call MakeVisible on any parent scrollable area that contains the element. 如果這個專案不包含在可捲動區域中, RequestBringIntoView仍會引發事件, 但不會有任何作用, 因為沒有事件接聽程式。If this element is not contained in a scrollable area, the RequestBringIntoView event is still raised, but there will be no effect because there are no event listeners.

另請參閱

適用於