WPFのコンボボックスの基本的な設定
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfCombo"
Title="Combobox example"
WindowStyle="ToolWindow"
Width="300"
Height="150">
<Window.Resources>
<local:ComboSource x:Key="languages">
<local:ComboData DisplayValue="C#" ItemValue="1" />
<local:ComboData DisplayValue="F#" ItemValue="2" />
<local:ComboData DisplayValue="Java" ItemValue="3" />
</local:ComboSource>
</Window.Resources>
<StackPanel>
<ComboBox Width="100"
ItemsSource="{Binding Source={StaticResource ResourceKey=languages}}"
DisplayMemberPath="DisplayValue"
SelectedValuePath="ItemValue"
SelectedValue="{Binding Path=ProgramLanguage}"
/>
</StackPanel>
</Window>
namespace WpfCombo
{
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
class ComboSource : ObservableCollection<ComboData>
{
}
class ComboData
{
public string DisplayValue { get; set; }
public string ItemValue { get; set; }
}
}