【发布时间】:2019-03-12 07:54:48
【问题描述】:
我正在制作图书馆管理软件。当用户点击一本书时,我想显示关于这本书的完整信息。 Book 类型的属性之一是标签。因为一本书可能有很多标签,所以我决定使用列表视图来显示标签。
我想在列表视图中选择标签。我该怎么做?我找到了this question。接受的答案说使用一种方法ListView.Select(),不幸的是它不存在。此外,ListView.Items[0].Selected = true; 不会编译。这是错误:
错误 CS1061“object”不包含“Selected”的定义,并且找不到接受“object”类型的第一个参数的可访问扩展方法“Selected”(您是否缺少 using 指令或程序集引用?)
编辑:有人要代码。在这里。
这是列表视图:
<ListView x:Name="TagsListView"
SelectionMode="Multiple"
ItemsSource="{x:Bind Tags}"
Grid.Row="4"
Grid.Column="1"/>
这是后面的代码:
public sealed partial class BookInfo_View : Page
{
//don't worry about DataAccess.
private Book book = new Book();
private List<string> Tags = DataAccess.GetTags();
public BookInfo_View()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
book = (Book)e.Parameter;
//dont worry about how this works. This line of code gives me the tags
string[] selectedTags = book.Tags.Split(';', System.StringSplitOptions.RemoveEmptyEntries);
//here i want to select the selected tags
}
}
这是书类:
public class Book
{
public string Title { get; set; }
public string Author { get; set; }
public string Publisher { get; set; }
public string ISBN { get; set; }
public int Quantity { get; set; }
public string CoverImageLocation { get; set; }
public string Tags { get; set; }
}
编辑:我觉得你们没有理解这个问题。问题是
ListView.Items[0].Selected = true;
上面这行代码无法编译!它给出了上面提到的错误
【问题讨论】: