Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 什么';这是访问WPF DataTemplate中随机数个控件的最佳方法_C#_Wpf_Binding - Fatal编程技术网

C# 什么';这是访问WPF DataTemplate中随机数个控件的最佳方法

C# 什么';这是访问WPF DataTemplate中随机数个控件的最佳方法,c#,wpf,binding,C#,Wpf,Binding,我正在构建一个调查问卷应用程序,向用户显示一系列问题 为了简化模型,问题由 class Question{ String name; bool ComboBox; String[] choices; } 在代码隐藏中,我有一个DataContext使用的ObservableCollection XAML看起来像这样 ... <ItemsControl ItemsSource="{Binding}" ItemTemplateSelector="{...}">

我正在构建一个调查问卷应用程序,向用户显示一系列问题

为了简化模型,问题由

class Question{
    String name;
    bool ComboBox;
    String[] choices;
}
在代码隐藏中,我有一个DataContext使用的ObservableCollection

XAML看起来像这样

...
<ItemsControl ItemsSource="{Binding}" ItemTemplateSelector="{...}">
</ItemsControl>
。。。
ItemTemplateSelector根据问题对象中指定的属性组合框选择ItemTemplate。一个ItemTemplate显示组合框中的字符串[]选项,另一个创建与数组中字符串数量相同的文本框


收集用户插入的所有数据的最佳方法是什么。

最简单的方法是将答案也放在问题类中。用户填写完问卷后,只需遍历您的集合即可获得答案。 再添加一个属性,如AnsweredIndex,以保存用户选择的索引