<Window x:Class="demo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:db="clr-namespace:StoreDatabase;assembly=StoreDatabase"
xmlns:local="clr-namespace:demo"
Title="WrappedList" Height="308" Width="383"
>
<Window.Resources>
<local:ImagePathConverter x:Key="ImagePathConverter"></local:ImagePathConverter>
<!--数据模板-->
<DataTemplate x:Key="ItemTemplate">
<Grid >
<Grid.ColumnDefinitions>
<!--每一个列表项的宽度都一样-->
<ColumnDefinition SharedSizeGroup="SingleWidthColumn"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.Style>
<Style>
<Setter Property="TextBlock.Foreground" Value="red"></Setter>
</Style>
</Grid.Style>
<Border Margin="5" BorderThickness="10" BorderBrush="Green"
CornerRadius="4">
<StackPanel Margin="3">
<TextBlock Text="{Binding Path=ModelName}" HorizontalAlignment="Center"></TextBlock>
<Image Source="{Binding Path=ProductImagePath, Converter={StaticResource ImagePathConverter}}"
Width="80"
></Image>
</StackPanel>
</Border>
</Grid>
</DataTemplate>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Button Margin="7,7,7,0" Padding="2" Click="cmdGetProducts_Click">Get Products</Button>
<!--列表框都有ScrollViewer.HorizontalScrollBarVisibility(水平滚动条),-->
<ListBox Grid.IsSharedSizeScope="True" Grid.Row="1" Margin="7,3,7,10" Name="lstProducts" ItemTemplate="{StaticResource ItemTemplate}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel></WrapPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</Grid>
</Window>
![image_thumb4_thumb image_thumb4_thumb](//images0.cnblogs.com/blog/479302/201411/010052076906926.png)
<Window x:Class="demo.ComboBoxSelectionBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ComboBoxSelectionBox" Height="300" Width="300"
xmlns:local="clr-namespace:demo"
>
<Window.Resources>
<local:ImagePathConverter x:Key="ImagePathConverter"></local:ImagePathConverter>
</Window.Resources>
<StackPanel Margin="5">
<!--IsEditable是否允许输入内容,自动补充-->
<!--IsReadOnly禁用文本搜索-->
<ComboBox SnapsToDevicePixels="True" Name="lstProducts"
IsEditable="{Binding ElementName=chkIsEditable, Path=IsChecked}"
IsReadOnly="{Binding ElementName=chkIsReadOnly, Path=IsChecked}"
IsTextSearchEnabled="False" Margin="5" HorizontalAlignment="Stretch">
<ComboBox.ItemContainerStyle>
<Style>
<Setter Property="Control.Padding" Value="1"></Setter>
<Style.Triggers>
<Trigger Property="ComboBoxItem.IsSelected" Value="True">
<Setter Property="ComboBoxItem.Background" Value="red" />
</Trigger>
<Trigger Property="ComboBoxItem.IsHighlighted" Value="True">
<Setter Property="ComboBoxItem.Background" Value="Yellow" />
</Trigger>
</Style.Triggers>
</Style>
</ComboBox.ItemContainerStyle>
<ComboBox.ItemTemplate>
<DataTemplate>
<Grid Margin="0" Background="White">
<Border Margin="5" BorderThickness="1" BorderBrush="Pink"
Background="{Binding RelativeSource=
{
RelativeSource
Mode=FindAncestor,
AncestorType={x:Type ComboBoxItem}
},
Path=Background
}" CornerRadius="4">
<Grid Margin="3">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock FontWeight="Bold" Text="{Binding Path=ModelNumber}"></TextBlock>
<TextBlock Grid.Row="1" Text="{Binding Path=ModelName}"></TextBlock>
<Image Grid.Column="1" Grid.RowSpan="2" Width="50" Source="{Binding Path=ProductImagePath, Converter={StaticResource ImagePathConverter}}"></Image>
</Grid>
</Border>
</Grid>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<CheckBox Name="chkIsEditable" Margin="5">IsEditable</CheckBox>
<CheckBox Name="chkIsReadOnly" Margin="5">IsReadOnly</CheckBox>
</StackPanel>
</Window>