Почему Listview Itemtemplate быстрее, чем ViewBase? - PullRequest
0 голосов
/ 03 апреля 2019

У меня есть WPF ListView и два сценария для привязки данных следующим образом:

  1. Настройка 'ItemTemplate'

    ItemTemplate = "{DynamicResource MyCustomDataTemplate}"

  2. Настройка 'ViewBase'

    ListView.View = MyCustomView

И «MyCustomView» выглядит следующим образом:

<local:TileView x:Key="MyCustomView" ItemTemplate="{StaticResource MyCustomDataTemplate}"  CornerRadius="4" SelectionBrush="#FFF18C00" />

Я использую «ViewBase», потому что мне нужны некоторые дополнительные данные, такие как кисть выбора и другие, а также «TileView» наследуется от класса «ViewBase».

вопрос теперь в том, почему сценарий нет. 1 очень очень быстро, чем сценарий № 2? это означает, что для 4000 элементов первый сценарий загружает все элементы в течение 4 секунд, а второй сценарий - около одной минуты.

Мне нужно использовать второй сценарий ради его дополнительных функций.

Любая помощь, чтобы сделать это быстрее?


для получения дополнительной информации о 'TileView':

Public Class TileView
Inherits ViewBase
Private _itemTemplate As DataTemplate
Private _SelectionBrush As Brush = Brushes.Transparent
Private _CornerRadius As New CornerRadius(0)

Public Shared ReadOnly SelectionBrushProerty As DependencyProperty = DependencyProperty.Register("SelectionBrush", GetType(Brush), GetType(TileView))
   Public Shared ReadOnly ItemContainerStyleProperty As DependencyProperty = ItemsControl.ItemContainerStyleProperty.AddOwner(GetType(TileView))
Public Property ItemContainerStyle() As Style
    Get
        Return CType(GetValue(ItemContainerStyleProperty), Style)
    End Get
    Set(ByVal value As Style)
        SetValue(ItemContainerStyleProperty, value)
    End Set
End Property
Public Property ItemTemplate() As DataTemplate
    Get
        Return _itemTemplate
    End Get
    Set(ByVal value As DataTemplate)
        _itemTemplate = value
    End Set
End Property
Public Property SelectionBrush() As Brush
    Get
        Return MyBase.GetValue(SelectionBrushProerty)
    End Get
    Set(ByVal value As Brush)
        MyBase.SetValue(SelectionBrushProerty, value)
    End Set
End Property

Protected Overrides ReadOnly Property DefaultStyleKey() As Object
    Get
        Return New ComponentResourceKey([GetType](), "TileView")
    End Get
End Property
Protected Overrides ReadOnly Property ItemContainerDefaultStyleKey() As Object
    Get
        Return New ComponentResourceKey([GetType](), "TileViewItem")
    End Get
End Property
  Public Property CornerRadius As CornerRadius
    Get
        Return _CornerRadius
    End Get
    Set(value As CornerRadius)
        _CornerRadius = value
    End Set
End Property  

EndClass

И нет необходимости иллюстрировать структуру MyCustomDataTemplate, потому что она одинакова в двух сценариях.

Спасибо вам всем.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...