Define ListBox template : ListBox Style « Windows Presentation Foundation « VB.Net Tutorial






<Window x:Class="Main"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib" 
    Title="">
  <Window.Resources>
    <x:ArrayExtension Type="{x:Type sys:String}"  x:Key="items">
      <sys:String>A</sys:String>
      <sys:String>B</sys:String>
      <sys:String>C</sys:String>
      <sys:String>D</sys:String>
    </x:ArrayExtension>
  </Window.Resources>
  <ListBox ItemsSource="{StaticResource items}" Width="120" Height="67">
    <ListBox.Template>
      <ControlTemplate TargetType="{x:Type ListBox}">
        <Border BorderThickness="1" BorderBrush="Black" CornerRadius="10">
          <ScrollViewer>
            <ScrollViewer.Clip>
              <RectangleGeometry Rect="0, 0, 100, 50"></RectangleGeometry>
            </ScrollViewer.Clip>
            <VirtualizingStackPanel IsItemsHost="True" />
          </ScrollViewer>
        </Border>
      </ControlTemplate>
    </ListBox.Template>
  </ListBox>
</Window>
WPF Define List Box Template








16.29.ListBox Style
16.29.1.External ListBox styleExternal ListBox style
16.29.2.Define ListBox templateDefine ListBox template
16.29.3.Create a ListBoxItem, set font, content, add the ListBoxItem to the ListBoxCreate a ListBoxItem, set font, content, add the ListBoxItem to the ListBox
16.29.4.Change HeightChange Height
16.29.5.Change MinHeightChange MinHeight
16.29.6.Create a style that will produce a horizontal ListBox.Create a style that will produce a horizontal ListBox.