FrameworkElement.BringIntoView Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Attempts to bring this element into view, within any scrollable regions it is contained within.
Overloads
BringIntoView(Rect) |
Attempts to bring the provided region size of this element into view, within any scrollable regions it is contained within. |
BringIntoView() |
Attempts to bring this element into view, within any scrollable regions it is contained within. |
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)
Parameters
- targetRectangle
- Rect
Specified size of the element that should also be brought into view.
Examples
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
Remarks
By calling this method, you raise a RequestBringIntoView event that originates from the current element. This event is raised so that it can be handled by a ScrollViewer, or a derived or similar class. 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. 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. Reasons for failure can include the element settings, such as Visibility being some value other than Visible.
If you use the signature that does not specify a targetRectangle
, then the entire element size (its RenderSize) will be made visible.
By calling this method, you potentially will call MakeVisible on any parent scrollable area that contains the element. 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.
See also
Applies to
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 ()
Examples
The following example implements a handler for an application navigation event that responds whenever the uniform resource identifier (URI) being navigated to includes a fragment. The fragment is named in the URI following the hash sign (#), and the implemented behavior causes the element to scroll into view within the frame. 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
Remarks
By calling this method, you raise a RequestBringIntoView event that originates from the current element. This event is raised so that it can be handled by a ScrollViewer, or a derived or similar class. 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. 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. Reasons for failure can include the element settings, such as Visibility being some value other than Visible.
If you use the signature that does not specify a targetRectangle
, then the entire element size (its RenderSize) will be made visible.
By calling this method, you potentially will call MakeVisible on any parent scrollable area that contains the element. 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.