如何在返回到框架后在 UWP C# 中重新填充列表框
本文关键字:填充 新填充 列表 返回 框架 UWP | 更新日期: 2023-09-27 18:30:23
我有复合设置,可以重新填充文本框和文本块的数据,但在尝试重新填充列表框时失败。下面是一些代码:在"OnNavigatedTo"中
{
ApplicationDataCompositeValue composite = (ApplicationDataCompositeValue)localSettings.Values["CompositeSettings"];
if (composite == null)
{
MessageBox("No data!");
}
else
{
txtBox1.Text = composite["text1"]?.ToString();
txtBox2.Text = composite["text2"]?.ToString();
//Here are the issues
lstOfData1.ItemsSource = composite["myListOfData1"]?.ToString();
lstOfData2.ItemsSource = composite["myListOfData2"]?.ToString();
}
在"导航源"中
{
ApplicationDataCompositeValue composite = new ApplicationDataCompositeValue();
composite["text1"] = txtBox1.Text;
composite["text2"] = txtBox2.Text;
composite["myListOfData1"] = myListOfData1;
composite["myListOfData2"] = myListOfData2;
localSettings.Values["CompositeSettings"] = composite;
}
因此,txtBoxes可以很好地重新填充,但列表框是空的。我是否通过复合设置进行排序?如何?
myListOfData1 和 myListOfData2 应该是某种集合,但在 OnNavigatingTo 方法中,您正在将它们转换为字符串。这适用于文本框,因为 Text 属性是一个字符串。
你只需要把它转换为正确的类型,例如List