![](/img/trans.png)
[英]What's the best way of creation of thousands of controls in scrollable area using WPF
[英]What's the best way of access a random number of controls in WPF DataTemplate
我正在构建一个问卷调查应用程序,向用户显示一系列问题。
为了简化模型,问题用
class Question{
String name;
bool ComboBox;
String[] choices;
}
在后面的代码中,我有一个由DataContext使用的ObservableCollection。
XAML看起来像这样
...
<ItemsControl ItemsSource="{Binding}" ItemTemplateSelector="{...}">
</ItemsControl>
ItemTemplateSelector根据Question对象中指定的属性ComboBox选择ItemTemplate。 一个ItemTemplate显示ComboBox内的String []选择,另一个ItemTemplate创建与数组中String数量一样多的TextBox。
收集用户插入的所有数据的最佳方法是什么。
最简单的方法是在Question类中也有答案。 用户填写调查表后,只需遍历您的集合即可获得答案。 再添加一个属性,例如AnsweredIndex,以保存用户选择的索引。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.