您很可能希望使用 aListBox
及其元素(您的文本框和所需数量的标签)通过数据绑定绑定到视图模型。我希望您熟悉 XAML 和 C# 中的数据绑定,但如果不熟悉,请查看此内容。
因此,我将创建一个ListBox
属性ItemsSource
数据绑定到 的实例ObservableCollection
,其中包含列表视图的视图模型。
<ListBox ItemsSource="{Binding GPAItems}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding GPAItemLabel}" />
<TextBox Text="{Binding GPAItemText, Mode=TwoWay}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
是,GPAItems
是:ObservableCollection<GPAItem>
GPAItem
class GPAItem: INotifyPropertyChanged
{
...
public string GPAItemLabel {get; set;}
public string GPAItemText {get; set;}
}
上面的代码没有经过测试(我只是在浏览器中为你编写的),但你应该从这里得到这个想法。同样,数据绑定和 MVVM 体系结构的知识对任何 Windows Phone 开发人员都非常有益,所以检查一下,大多数问题都会消失。