Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法设置数据绑定列表框的SelectedListIndex属性,原因是什么?_C#_Windows Phone 7_Listbox - Fatal编程技术网

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();