我試圖用項目填充列表框。該ItemsSource
如下:WPF .NET4.0列表框和ItemsControl
public SortedDictionary<string, List<int>> AvailableValues
時,我有以下的項目
似乎很好地奠定了。除了我不能選擇一個整體項目,並執行一些功能。
<ScrollViewer Grid.Row="0" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" >
<ItemsControl ItemsSource="{Binding AvailableValues}">
<ItemsControl.Template>
<ControlTemplate>
<CustomControls:UniformWrapPanel IsItemsHost="True"/>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="60"/>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Content="{Binding Key}" />
<ComboBox Grid.Row="0" Grid.Column="1" ItemsSource="{Binding Value}" SelectedItem="{Binding SelectedInputValue, UpdateSourceTrigger=PropertyChanged}" IsSynchronizedWithCurrentItem="True" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
伊夫試圖替換ItemsControl
與ListBox
(以及ListBox.ItemTemplate
)和不能似乎得到其中由Label
Content
是左對齊的顯示和Combobox
內容是正確的對齊。
UniformWrapPanel
來自CodeProject文章。
感謝,
Thanks @randyc。奇怪的是,即使使用上面的定義,它的情節也是如此,但是在'Oriention'設置爲'Horizontal'的情況下,兩個項目包含在一個StackPanel中。然而,上面的定義有訣竅! – TheRenoRanger 2011-05-23 02:23:44