Compartilhar via


Otimização de desempenho: Outras recomendações

This topic provides performance recommendations in addition to the ones covered by the topics in the Optimizing WPF Application Performance section.

This topic contains the following sections:

  • Opacity on Brushes Versus Opacity on Elements

  • Navigation to Object

  • Hit Testing on Large 3D Surfaces

  • CompositionTarget.Rendering Event

  • Avoid Using ScrollBarVisibility=Auto

  • Configure Font Cache Service to Reduce Start-up Time

Opacity on Brushes Versus Opacity on Elements

When you use a Brush to set the Fill or Stroke of an element, it is better to set the Brush.Opacity value rather than the setting the element's Opacity property. Modifying an element's Opacity property can cause WPF to create a temporary surface.

The NavigationWindow object derives from Window and extends it with content navigation support, primarily by aggregating NavigationService and the journal. You can update the client area of NavigationWindow by specifying either a uniform resource identifier (URI) or an object. The following sample shows both methods:

        Private Sub buttonGoToUri(ByVal sender As Object, ByVal args As RoutedEventArgs)
            navWindow.Source = New Uri("NewPage.xaml", UriKind.RelativeOrAbsolute)
        End Sub

        Private Sub buttonGoNewObject(ByVal sender As Object, ByVal args As RoutedEventArgs)
            Dim nextPage As New NewPage()
            nextPage.InitializeComponent()
            navWindow.Content = nextPage
        End Sub
private void buttonGoToUri(object sender, RoutedEventArgs args)
{
    navWindow.Source = new Uri("NewPage.xaml", UriKind.RelativeOrAbsolute);
}

private void buttonGoNewObject(object sender, RoutedEventArgs args)
{
    NewPage nextPage = new NewPage();
    nextPage.InitializeComponent();
    navWindow.Content = nextPage;
}

Each NavigationWindow object has a journal that records the user's navigation history in that window. One of the purposes of the journal is to allow users to retrace their steps.

When you navigate using a uniform resource identifier (URI), the journal stores only the uniform resource identifier (URI) reference. This means that each time you revisit the page, it is dynamically reconstructed, which may be time consuming depending on the complexity of the page. In this case, the journal storage cost is low, but the time to reconstitute the page is potentially high.

When you navigate using an object, the journal stores the entire visual tree of the object. This means that each time you revisit the page, it renders immediately without having to be reconstructed. In this case, the journal storage cost is high, but the time to reconstitute the page is low.

When you use the NavigationWindow object, you will need to keep in mind how the journaling support impacts your application's performance. For more information, see Visão geral de navegação.

Hit Testing on Large 3D Surfaces

Hit testing on large 3D surfaces is a very performance intensive operation in terms of CPU consumption. This is especially true when the 3D surface is animating. If you do not require hit testing on these surfaces, then disable hit testing. Objects that are derived from UIElement can disable hit testing by setting the IsHitTestVisible property to false.

CompositionTarget.Rendering Event

The CompositionTarget.Rendering event causes WPF to continuously animate. If you use this event, detach it at every opportunity.

Avoid Using ScrollBarVisibility=Auto

Whenever possible, avoid using the ScrollBarVisibility.Auto value for the HorizontalScrollBarVisibility and VerticalScrollBarVisibility properties. These properties are defined for RichTextBox, ScrollViewer, and TextBox objects, and as an attached property for the ListBox object. Instead, set ScrollBarVisibility to Disabled, Hidden, or Visible.

The Auto value is intended for cases when space is limited and scrollbars should only be displayed when necessary. For example, it may be useful to use this ScrollBarVisibility value with a ListBox of 30 items as opposed to a TextBox with hundreds of lines of text.

Configure Font Cache Service to Reduce Start-up Time

O WPF dados de fontes de compartilhamentos de serviço de Cache de fonte entre WPF aplicativos. O primeiro WPF inicia o aplicativo que você executar esse serviço se o serviço não estiver sendo executado. Se você estiver usando Windows Vista, você pode definir o "Windows Presentation Foundation (WPF) Font Cache 3.0.0.0" serviço de "Manual" (padrão) para "Automático (inicialização atrasada)" para reduzir o tempo de inicialização inicial de WPF aplicativos.

Consulte também

Conceitos

Planejando para desempenho de aplicativos

Otimização de desempenho: Levando vantagens de hardware

Otimização de desempenho: Layout and Design

Otimização de desempenho: 2D Graphics and Imaging

Otimização de desempenho: Comportamento de objeto

Otimização de desempenho: Recursos do aplicativo

Otimização de desempenho: Texto

Otimização de desempenho: Ligação de Dados

Dicas e truques de animação