Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have looked out the tips that you can find on the internet and I just noticed there are no problems.</p> <p>The following things should be followed carefully, because otherwise the virtualization is gone (taken from MSDN, <a href="http://msdn.microsoft.com/en-us/library/cc716879.aspx" rel="nofollow">link</a>):</p> <ul> <li>Item containers are added directly to the ItemsControl. For example, if an application explicitly adds ListBoxItem objects to a ListBox, the ListBox does not virtualize the ListBoxItem objects.</li> <li>Setting CanContentScroll to false.</li> <li>Setting IsVirtualizing to false.</li> <li>Using item grouping.</li> </ul> <p>The following style works for me without problems.</p> <pre><code>&lt;Style x:Key="SimpleComboBox" TargetType="{x:Type ComboBox}"&gt; &lt;Setter Property="ItemsPanel"&gt; &lt;Setter.Value&gt; &lt;ItemsPanelTemplate&gt; &lt;VirtualizingStackPanel IsItemsHost="True" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling" KeyboardNavigation.DirectionalNavigation="Contained" /&gt; &lt;/ItemsPanelTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; &lt;ComboBox Name="cbTest" IsEditable="True" Style="{StaticResource SimpleComboBox}" /&gt; </code></pre> <p><br/> After I played around for a while with the style of <a href="http://kaxaml.com/" rel="nofollow">Kaxaml</a>, I noticed a small thing. With this style I've had problems when I used <code>IsEditable = "True"</code>, the performance goes down!</p> <p>The following style works for me perfect</p> <pre><code>&lt;Style x:Key="SimpleComboBox" TargetType="{x:Type ComboBox}"&gt; &lt;Setter Property="SnapsToDevicePixels" Value="true"/&gt; &lt;Setter Property="OverridesDefaultStyle" Value="true"/&gt; &lt;Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/&gt; &lt;Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/&gt; &lt;Setter Property="ScrollViewer.CanContentScroll" Value="true"/&gt; &lt;Setter Property="MinWidth" Value="120"/&gt; &lt;Setter Property="MinHeight" Value="20"/&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="{x:Type ComboBox}"&gt; &lt;Grid&gt; &lt;ToggleButton Name="ToggleButton" Focusable="false" ClickMode="Press" IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"&gt; &lt;ToggleButton.Template&gt; &lt;ControlTemplate TargetType="{x:Type ToggleButton}"&gt; &lt;Grid&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition /&gt; &lt;ColumnDefinition Width="20" /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Border x:Name="Border" Grid.ColumnSpan="2" CornerRadius="2" Background="#C0C0C0" BorderBrush="#404040" BorderThickness="1" /&gt; &lt;Border Grid.Column="0" CornerRadius="2,0,0,2" Margin="1" Background="#FFFFFF" BorderBrush="#404040" BorderThickness="0,0,1,0" /&gt; &lt;Path x:Name="Arrow" Grid.Column="1" Fill="#404040" HorizontalAlignment="Center" VerticalAlignment="Center" Data="M 0 0 L 4 4 L 8 0 Z"/&gt; &lt;/Grid&gt; &lt;ControlTemplate.Triggers&gt; &lt;Trigger Property="ToggleButton.IsMouseOver" Value="true"&gt; &lt;Setter TargetName="Border" Property="Background" Value="#808080" /&gt; &lt;/Trigger&gt; &lt;Trigger Property="ToggleButton.IsChecked" Value="true"&gt; &lt;Setter TargetName="Border" Property="Background" Value="#E0E0E0" /&gt; &lt;/Trigger&gt; &lt;Trigger Property="IsEnabled" Value="False"&gt; &lt;Setter TargetName="Border" Property="Background" Value="#EEEEEE" /&gt; &lt;Setter TargetName="Border" Property="BorderBrush" Value="#AAAAAA" /&gt; &lt;Setter Property="Foreground" Value="#888888"/&gt; &lt;Setter TargetName="Arrow" Property="Fill" Value="#888888" /&gt; &lt;/Trigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; &lt;/ToggleButton.Template&gt; &lt;/ToggleButton&gt; &lt;ContentPresenter Name="ContentSite" IsHitTestVisible="False" Content="{TemplateBinding SelectionBoxItem}" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" Margin="3,3,23,3" VerticalAlignment="Center" HorizontalAlignment="Left" /&gt; &lt;TextBox x:Name="PART_EditableTextBox" Style="{x:Null}" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="3,3,23,3" Focusable="True" Background="Transparent" Visibility="Hidden" IsReadOnly="{TemplateBinding IsReadOnly}"&gt; &lt;TextBox.Template&gt; &lt;ControlTemplate TargetType="{x:Type TextBox}"&gt; &lt;Border x:Name="PART_ContentHost" Focusable="False" Background="{TemplateBinding Background}" /&gt; &lt;/ControlTemplate&gt; &lt;/TextBox.Template&gt; &lt;/TextBox&gt; &lt;Popup Name="Popup" Placement="Bottom" IsOpen="{TemplateBinding IsDropDownOpen}" AllowsTransparency="True" Focusable="False" PopupAnimation="Slide"&gt; &lt;Grid Name="DropDown" SnapsToDevicePixels="True" MinWidth="{TemplateBinding ActualWidth}" MaxHeight="{TemplateBinding MaxDropDownHeight}"&gt; &lt;Border x:Name="DropDownBorder" Background="#FFFFFF" BorderThickness="1" BorderBrush="#888888"/&gt; &lt;ScrollViewer Margin="4,6,4,6" SnapsToDevicePixels="True"&gt; &lt;VirtualizingStackPanel IsItemsHost="True" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling" KeyboardNavigation.DirectionalNavigation="Contained" /&gt; &lt;/ScrollViewer&gt; &lt;/Grid&gt; &lt;/Popup&gt; &lt;/Grid&gt; &lt;ControlTemplate.Triggers&gt; &lt;Trigger Property="HasItems" Value="false"&gt; &lt;Setter TargetName="DropDownBorder" Property="MinHeight" Value="95"/&gt; &lt;/Trigger&gt; &lt;Trigger Property="IsEnabled" Value="false"&gt; &lt;Setter Property="Foreground" Value="#888888"/&gt; &lt;/Trigger&gt; &lt;!-- remove this trigger, because the virtualization is broken!!! &lt;Trigger Property="IsGrouping" Value="true"&gt; &lt;Setter Property="ScrollViewer.CanContentScroll" Value="false"/&gt; &lt;/Trigger&gt; --&gt; &lt;Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="true"&gt; &lt;Setter TargetName="DropDownBorder" Property="CornerRadius" Value="4"/&gt; &lt;Setter TargetName="DropDownBorder" Property="Margin" Value="0,2,0,0"/&gt; &lt;/Trigger&gt; &lt;Trigger Property="IsEditable" Value="true"&gt; &lt;Setter Property="IsTabStop" Value="false"/&gt; &lt;Setter TargetName="PART_EditableTextBox" Property="Visibility" Value="Visible"/&gt; &lt;Setter TargetName="ContentSite" Property="Visibility" Value="Hidden"/&gt; &lt;/Trigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;Style.Triggers&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; </code></pre> <p>I have also removed this trigger.</p> <pre><code>&lt;Trigger Property="IsGrouping" Value="true"&gt; &lt;Setter Property="ScrollViewer.CanContentScroll" Value="false"/&gt; &lt;/Trigger&gt; </code></pre> <p>Hope this helps</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload