ObservableCollectionにデータバインドされたComboBoxがあります。内容を並べ替えるまで、すべてがうまくいきました。sortdescriptionを使用してみましたが、ここで問題が発生しています。XAMLを助けてください
<ComboBox Margin="10,0,0,0" FontSize="16" Height="30" Width="200"
ItemsSource="{Binding Path=NationalityDropDownList}"
DisplayMemberPath="Description"
SelectedValuePath="Code"
SelectedIndex="{Binding Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Path=SelectedIndex}"
SelectedValue="{Binding Path=SelectedNationality, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Text="0">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding UpdateNationalityCodeCommand}"
CommandParameter="{Binding Path=SelectedIndex}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
CODE BEHIND
/// <summary>
/// NationalityDropDownList
/// </summary>
private CollectionView nationalityDropDownList;
/// <summary>
/// Gets or Sets the NationalityDropDownList
/// </summary>
public CollectionView NationalityDropDownList
{
get
{
SortDescription sd = new SortDescription("Description", ListSortDirection.Ascending);
nationalityDropDownList.SortDescriptions.Add(sd);
return nationalityDropDownList;
}
set
{
if (NationalityDropDownList != value)
{
nationalityDropDownList = value;
RaisePropertyChanged(() => NationalityDropDownList);
}
}
}
/// <summary>
/// Updates the Nationality Drop Down List information
/// </summary>
private void UpdateNationalityDropDownList()
{
// TODO: Currently hardcoded for Focus Group
IList<Nationality> list = new List<Nationality>();
Nationality nationality = new Nationality();
// TODO : This code should go through the hibernate Code table to read the list of Nationality.
IEnumerable<Code> nationalityList = localCodeLibrary.FindAllNationalities();
nationality.Code = string.Empty;
nationality.Description = "";
list.Add(nationality);
foreach (Code national in nationalityList)
{
nationality.Code = national.Id.Code;
nationality.Description = national.Description;
list.Add(nationality);
}
//nationalityDropDownList.SortDescriptions.Add(new SortDescription(nationality.Description, ListSortDirection.Ascending));
NationalityDropDownList = new CollectionView(list);
}