コンボボックスに追加するアイテムを作成するためのクラスを作成しました
public class ComboBoxItemClass
{
public string Text { get; set; }
public object Value { get; set; }
public override string ToString()
{
return Text;
}
}
コンボボックスの私のXAMLは次のとおりです
<TextBlock Text="State"/>
<ComboBox x:Name="cbState"/>
コード ビハインドの C# コードは次のとおりです。
private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
List<ComboBoxItemClass> state_items = new List<ComboBoxItemClass>();
List<State> states = Location.GetStates();
foreach(State s in states)
{
ComboBoxItemClass item = new ComboBoxItemClass() { Text = s.State_Name, Value = s.State_Id };
state_items.Add(item);
}
cbState.ItemsSource = state_items;
cbState.SelectedValue = 3;
エミュレータで実行中のコンボボックスは、選択された状態を示しません。クリックすると、状態のリストが表示されます。
デバッグ時に、selectedvalue に値を割り当てても null と表示されます。残りのコードに問題はなく、State_Id=3 の状態が存在します。