C# 无法设置数据绑定列表框的SelectedListIndex属性,原因是什么?
我避免问这个问题,但是列表框的选定索引无法设置。我已经阅读了其他线程并应用了设置,但它不起作用C# 无法设置数据绑定列表框的SelectedListIndex属性,原因是什么?,c#,windows-phone-7,listbox,C#,Windows Phone 7,Listbox,我避免问这个问题,但是列表框的选定索引无法设置。我已经阅读了其他线程并应用了设置,但它不起作用 <ListBox ItemsSource="{Binding}" HorizontalAlignment="Right" Name="lstReading" Height="Auto" SelectedIndex="{Binding
<ListBox ItemsSource="{Binding}"
HorizontalAlignment="Right"
Name="lstReading" Height="Auto"
SelectedIndex="{Binding BookmarkSelectedIndex}">
其中,IQText是一个
IEnumerable
,包括书签selectedIndex
作为数据元素。可以使用IQText中的其他数据元素,但无法设置listindex。有人能告诉我为什么吗?您是否在dictq
类中选择了书签索引?因此,每个项目(而不是每个集合)都有一个书签selectedIndex
您可以在dictq
之外创建单独的属性BookmarkSelectedIndex
,或者创建继承自observableCollection
的类,并具有其他属性BookmarkSelectedIndex
:
public class CollectionWithIndex: ObservalbeCollection<dictIQ>
{
public int BookmarkSelectedIndex { get; set; }
}
带有索引的公共类集合:observableCollection
{
public int BookmarkSelectedIndex{get;set;}
}
我希望您选择最适合您的解决方案在运行时将此代码用于选择项
List<Audio> lst = Audio.GetAudioFiles();
Audio aufile = new Audio { FileDisplayName = "Select Audio File" };
lst.Insert(0, aufile);
lstPickAudio.ItemsSource = lst;
string FileDisplayName="your condition"
lstPickAudio.SelectedItem = lst.Where(p => p.FileName == FileDisplayName).First();
List lst=Audio.GetAudioFiles();
Audio aufile=新建音频{FileDisplayName=“选择音频文件”};
lst.Insert(0,aufile);
lstPickAudio.ItemsSource=lst;
string FileDisplayName=“您的条件”
lstPickAudio.SelectedItem=lst.Where(p=>p.FileName==FileDisplayName).First();
BookmarkSelectedIndex在哪里声明?`public class dictqtext{public bool islanguageonetextlignmentright{get;set;}public bool IsLanguageTwoTextAlignmentRight{get;set;}public bool IsShowGrid{get;set;}public int BookmarkSelectedIndex{get;set;}其他一切正常,只有BookmarkSelectedIndex没有!请将代码编辑到您的问题中,以便正确格式化。好的,让代码变得更好并学习新技术总是好的。非常感谢。但为什么其他属性在工作而不是这个?我也是C#的新手,我尝试添加上面的代码,但在“ObservaleCollection”上出现了错误,因为它丢失了。ObservaleCollection拼写错误为什么其他属性正在工作而不是这个属性?
-如果每个项目都有一个书签SelectedIndex
,其中哪些属性将包含选定的索引?
List<Audio> lst = Audio.GetAudioFiles();
Audio aufile = new Audio { FileDisplayName = "Select Audio File" };
lst.Insert(0, aufile);
lstPickAudio.ItemsSource = lst;
string FileDisplayName="your condition"
lstPickAudio.SelectedItem = lst.Where(p => p.FileName == FileDisplayName).First();