ListBox中的comboBox显示问题
在listbox上定义的数据模板中存在一个comboBox,想使得comboBox初始化时默认加载其所在的分类,需要使用selectedItem通过数据绑定的形式来实现,现在出现错误index越界,求帮助???
绑定的代码:
<ComboBox Grid.Column="1" Grid.Row="1" Height="25" HorizontalAlignment="Left" Margin="8,0,0,0" Name="ComboBoxList" VerticalAlignment="Center" Width="190" ItemsSource="{Binding Source={x:Static cc:SubjectItemList.FolderName }}" Tag="{Binding}" SelectionChanged="ComboBoxList_SelectionChanged" DisplayMemberPath="FolderName" SelectedItem="{Binding .,Converter={StaticResource SubjectItemListConverter}}" ItemContainerStyle="{StaticResource CmbItemStyle}">
</ComboBox>
转换器的代码: //主要用于默认返回未分类的情况
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
Favorites returnValue = new Favorites() { ID = 0, FavoritesType = 1, FolderName = "未分类" };
return returnValue;
}
类型转化代码:
public override bool Equals(object obj)
{
bool returnValue = false;
if (obj != null && obj is Favorites)
{
returnValue = (ID == ((Favorites)obj).ID);
}
return returnValue;
}