I have a Silverlight application with a ComboBox that is filled by VideoCaptureDevice‘s.
cbVideoDevices.ItemsSource = CaptureDeviceConfiguration.GetAvailableVideoCaptureDevices();
I’m trying to add item, “Select a video device” to the first index but I can’t get it to work.
XAML Code:
<ComboBox Height="25" HorizontalAlignment="Left" Margin="0,0,0,0" Name="cbVideoDevices" VerticalAlignment="Top" Width="125" ItemsSource="{Binding AudioDevices}" SelectedItem="{Binding SelectedAudioDevice}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding FriendlyName}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Your explicitly setting the
ItemsSourcein the code behind and the XAML, choose one or the other. Ideally you would take the XAML approach and set theDataContextappropriately.Once you make that decision you can insert an item within your
ComboBoxby using theItemsproperty.A better approach would be to leverage the ICollectionView and simply sort the data and let the UI respond accordingly. Your
ItemsSourcewould then be bound to theICollectionView.