Why ContentPresenter's render time is bigger than its children's sum?

196 views Asked by At

See the below picture:

ContentPresenter's render time is bigger than others

I just used Performance Profiler in VS2017 and i found that the listBoxItem's ContentPresenter render time is so bigger than its children's.

I have to reduce total render time (which is 1.1s roughly). Sum of ListBoxItems render time is also 1.1s.

I don't know why time difference is made.

The Listbox's visual tree is like this:

  • ListBox(3057)
    • Border(3056)
      • ScollViewer(3055)
        • Grid(3054)
          • ScrollContentPresenter(3031)
            • ItemsPresenter(3029)
              • VirtualizingStackPanel(3028)
                • ListBoxItem(120)
                • ListBoxItem(84) ...
1

There are 1 answers

0
charles kim On

I can reduce visual tree's Control.

The way that i do is "redefine some Control's ControlTemplate"

Before redefine ControlTemplate, my ListBoxItem have Bd(Border), ContentPresenter, Grid,, etc. like below Visual Tree

After redefine ControlTemplate like below xaml

<ListBox.ItemContainerStyle>
    <Style TargetType="{x:Type ListBoxItem}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListBoxItem">
                    <ContentPresenter>
                         <ContentPresenter.Style>
                             <Style TargetType="{x:Type ContentPresenter}">
                                 <Setter Property="VirtualizingPanel.IsVirtualizing" Value="True"/>
                                 <Setter Property="VirtualizingPanel.VirtualizationMode" Value="Recycling"/>
                              </Style>
                          </ContentPresenter.Style>
                      </ContentPresenter>
                  </ControlTemplate>
              </Setter.Value>
          </Setter>
      </Style>
  </ListBox.ItemContainerStyle>

Then i can remove "Bd"(Border) like below.

  • ListBoxItem
    • ContentPresenter
      • Grid ...

To reduce render time, I will find useless Controls and remove.