我有一个页面生成许多元素,如textblock,listpicker等,基于JSON响应与C#,而不是XAML。所以,它是非常动态的页面。示例(仅适用于Listpicker):
public partial class MainPage : PhoneApplicationPage
{
public MainPage()
{
InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
Generate();
}
void Generate()
{
stack.Children.Clear(); // in XAML, I just put stackpanel
//in example I have array of string
string[] test = {"a","b","c","d","e","f"};
ListPicker list = new ListPicker();
for (int i = 0; i < test.Count(); i++)
{
list.Items.Add(test[i]);
}
//I want to keep in fullmode
list.ExpansionMode = ExpansionMode.FullScreenOnly;
sp.Children.Add(list);
}
问题是,当我在完整模式下选择列表项时,Listpicker所选项目不会更改。
如果ListPicker SelectedIndex Not Shown Correctly in WP7
我意识到我的问题出在OnNavigatedTo
,但我找不到在cs上创建的Listpicker的解决方案,而不是XAML。
有人能帮助我吗?