I am making a library management software. When the user clicks on a book, I want to display the full information about the book. One of the properties of the type Book is Tags. Because a book may have many tags, I decided to use a list view to display the tags.
I want to select the tags in the list view. How do I do it? I found this question. The accepted answer says to use a method ListView.Select()
which unfortunately does not exist. Also, ListView.Items[0].Selected = true;
does not compile. This is the error:
Error CS1061 'object' does not contain a definition for 'Selected' and no accessible extension method 'Selected' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
Edit: Someone asked for code. Here it is.
This is the listview:
<ListView x:Name="TagsListView"
SelectionMode="Multiple"
ItemsSource="{x:Bind Tags}"
Grid.Row="4"
Grid.Column="1"/>
this is the code behind:
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
}
}
This is the book class:
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; }
}
Edit: I feel you people did not understand the question. The problem is that
ListView.Items[0].Selected = true;
The above line of code does not compile! It gives the error mentioned above