Silverlight中的多列组合框

Silverlight中的多列组合框

本文介绍了Silverlight中的多列组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨Amigos,

任何人都可以建议我在Silverlight组合框中显示多个列的方法,并在下拉列表中显示标题.

我可以使用datatemplate获取多个列,但这会使组合框显示完整的多列行,并且不会将控件的displaymemberpath设置为单个列.

Hi Amigos,

Can any one suggest me a way to display multiple columns in silverlight combo box with headers in the dropdown list.

I can get the multiple columns using a datatemplate, but this causes the combobox to display the full multi-column row and won''t alow the controls displaymemberpath be set to a single column.

<ComboBox Height="20"  HorizontalAlignment="Left" Margin="856,35,0,0"  VerticalAlignment="Top" Width="115" >
                        <ComboBox.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding Name, Mode=OneWay}" />
                                    <TextBlock Text=" " />
                                    <TextBlock Text="{Binding Age, Mode=OneWay}" />
                                </StackPanel>
                            </DataTemplate>
                        </ComboBox.ItemTemplate>
                    </ComboBox>

推荐答案

<ComboBox Name="cb" Grid.IsSharedSizeScope="True" ItemsSource="{DynamicResource items}">
    <ComboBox.Resources>
        <CompositeCollection x:Key="items">
            <ComboBoxItem IsEnabled="False">
                <Grid TextElement.FontWeight="Bold">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition SharedSizeGroup="A"/>
                        <ColumnDefinition Width="5"/>
                        <ColumnDefinition SharedSizeGroup="B"/>
                    </Grid.ColumnDefinitions>
                    <Grid.Children>
                        <TextBlock Grid.Column="0" Text="Name"/>
                        <TextBlock Grid.Column="2" Text="Occupation"/>
                    </Grid.Children>
                </Grid>
            </ComboBoxItem>
            <Separator/>
            <CollectionContainer Collection="{Binding Source={x:Reference cb}, Path=DataContext.Data}"/>
        </CompositeCollection>

        <DataTemplate DataType="{x:Type obj:Employee}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition SharedSizeGroup="A"/>
                    <ColumnDefinition Width="5"/>
                    <ColumnDefinition SharedSizeGroup="B"/>
                </Grid.ColumnDefinitions>
                <Grid.Children>
                    <TextBlock Grid.Column="0" Text="{Binding Name}"/>
                    <TextBlock Grid.Column="2" Text="{Binding Occupation}"/>
                </Grid.Children>
            </Grid>
        </DataTemplate>
    </ComboBox.Resources>
</ComboBox>



这篇关于Silverlight中的多列组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 23:34