I have a User Control which have multiple labels containing values, such as a date for Uploaded, a string for Title, a string for Author, ect. As of right now I'm populating the stackpanel by creating a new instance of the user control for each row of data in the SQL database.
What I would like is to click on a "Sort by Date" button and have all the instances of the User Control object sort by the Uploaded Date in the Stackpanel.
How would I procced going with this?
Some of the code behind populating the stackpanel with new instances of the User Control.
/// <summary>
/// Receive data from SQL and apply them to a new instance of itemControl
/// </summary>
public static void GetResultItems(StackPanel stackPanel)
{
// The SQL Query
string Query = "select * from Items";
MySqlCommand command = new MySqlCommand(Query, connection);
// Open connection
connection.Open();
MySqlDataReader reader = command.ExecuteReader();
// While reading...
while (reader.Read())
{
// Creates new instance of the itemControl
ItemControl itemControl = new ItemControl();
// Assign the data from the SQL database onto the itemControl labels
//Upload Date. This contains the date for when it was Uploaded.
itemControl.lblListUploaded.Content = (reader["UploadDate"].ToString()); //I wish to use this value to sort by
//Author
itemControl.lblExpandAuthor.Content = "Author: " + (reader["Author"].ToString());
// Add the new instance of ItemControl to the resultItem List<>
//The list is never used, but is created incase of later usage/need.
resultItem.Add(itemControl);
// Add the item to the Stackpanel
stackPanel.Children.Add(itemControl);
}
// Close connection
connection.Close();
}
}