Я заполняю ComboBox
Item Source
List
.
Я использую DisplayMemberPath="Name"
, чтобы отобразить имена элементов в раскрывающемся меню.
Отображение имени перестает работатькогда я применяю пользовательский XAML ItemContainerStyle
к ComboBox
.
без стиля:
с ItemContainerStyleПрименено:
ComboBox
<ComboBox x:Name="cboAudioSampleRate"
Style="{DynamicResource ComboBoxBlue}"
ItemContainerStyle="{DynamicResource ComboBoxBlueItem}" <-- Problem
ItemsSource="{Binding AudioSampleRate_Items}"
DisplayMemberPath="Name"
SelectedValuePath="Name"
SelectedIndex="{Binding AudioSampleRate_SelectedIndex}"
SelectedValue="{Binding AudioSampleRate_SelectedItem}"
IsEnabled="{Binding AudioSampleRate_IsEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Width="105"
Height="22"
SelectionChanged="cboAudioSampleRate_SelectionChanged"
ToolTip="Audio Sample Rate"
Grid.Column="2"
Grid.Row="6"
Margin="0,2,0,0"/>
Просмотреть модель
public class AudioSampleRate
{
public string Name { get; set; }
public string Frequency { get; set; }
}
public List<AudioSampleRate> _AudioSampleRate_Items = new List<AudioSampleRate>();
public List<AudioSampleRate> AudioSampleRate_Items
{
get { return _AudioSampleRate_Items; }
set
{
_AudioSampleRate_Items = value;
OnPropertyChanged("AudioSampleRate_Items");
}
}
Элемент списка источников
public static List<ViewModel.AudioSampleRate> sampleRate = new List<ViewModel.AudioSampleRate>()
{
new ViewModel.AudioSampleRate() { Name = "auto", Frequency = "" },
new ViewModel.AudioSampleRate() { Name = "8k", Frequency = "8000" },
new ViewModel.AudioSampleRate() { Name = "11.025k", Frequency = "11025" },
new ViewModel.AudioSampleRate() { Name = "12k", Frequency = "12000" },
new ViewModel.AudioSampleRate() { Name = "16k", Frequency = "16000" },
new ViewModel.AudioSampleRate() { Name = "22.05k", Frequency = "22050" },
new ViewModel.AudioSampleRate() { Name = "24k", Frequency = "24000" },
new ViewModel.AudioSampleRate() { Name = "32k", Frequency = "32000" },
new ViewModel.AudioSampleRate() { Name = "44.1k", Frequency = "44100" },
new ViewModel.AudioSampleRate() { Name = "48k", Frequency = "48000" }
};
Стиль элемента
<!-- ComboBox Blue Item -->
<Style x:Key="ComboBoxBlueItem" TargetType="{x:Type ComboBoxItem}">
<Setter Property="Template" Value="{StaticResource ComboBoxBlue.Item.ControlTemplate}"/>
<Setter Property="Foreground" Value="#FFFFFFFF" />
<Setter Property="Background" Value="#FF1049BB" />
<Setter Property="BorderBrush" Value="#FF1049BB" />
<Style.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter Property="Background" Value="#FF1049BB" />
</Trigger>
</Style.Triggers>
</Style>