语言

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 逻辑进入视图。 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 事件,但不会产生任何影响,因为没有事件侦听器。

另请参阅

适用于