0

コンボボックスに itens を追加したいのですが、同じコンボボックスを常に追加したくないので、c# で使用します。私のコードは、itens を追加したいコンボボックスです。

    <ScrollViewer Margin="252,130,296,134" Grid.Row="1" VerticalAlignment="Top" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollMode="Enabled" ScrollViewer.HorizontalScrollMode="Disabled" ScrollViewer.ZoomMode="Disabled">
            <StackPanel >
                <ItemsControl x:Name="ic" Grid.Row="2">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Grid HorizontalAlignment="Left" VerticalAlignment="Center">
                                <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                                    <Border BorderBrush="#C83245" Background="White"  BorderThickness="1">
                                        <ComboBox x:Name="cbSeletion" VerticalAlignment="Center" FontSize="14" Width="250" Height="40" Foreground="Black" Tapped="cbSeletion_Tapped">

                                        </ComboBox>
                                    </Border>
                                    <Border BorderBrush="#C83245" Background="White" BorderThickness="1">
                                        <TextBlock Text="{Binding Name}" FontSize="14" VerticalAlignment="Center" Width="350" Foreground="Black"/>
                                    </Border>
                                    <Border BorderBrush="#C83245" Background="White"  BorderThickness="1" >
                                        <TextBlock Text="{Binding Position}" FontSize="14" VerticalAlignment="Center" Width="250" Foreground="Black"/>
                                    </Border>
                                </StackPanel>
                            </Grid>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
            </StackPanel>
        </ScrollViewer>

使用するにはどうすればよいですか?

4

2 に答える 2

0

アイテムが本当に少ない場合はComboBoxItem、XAML で直接使用できますが、それでもそれほどエレガントではありません。MVVM アプローチは間違いなく答えです。特に ComboBox のコレクション内の多くのアイテムの場合は、柔軟性が向上し、ロジックがそれほどハードコードされていないためです。

于 2013-10-04T16:39:17.613 に答える