WPF - 用户控件中 DataGrid 的 ComboBox 列帮助
我有一个 MainWindow.xaml (由 TabControl 组成)和一些 UserControls (加载到 TabItems 中)。 一个特定的 UserControl 具有带有自定义列(不是自动生成的)的 WPFToolkit DataGrid。其中一列是 ComboBox 类型的列,它绑定到我的模型中名为“Status”的属性。我还有一个名为“FollowUpStatus”的状态枚举。此 ComboBox 列声明如下:
<WpfTK:DataGridComboBoxColumn
Header="Status"
SelectedItemBinding="{Binding Status}"
ItemsSource="{Binding Source={StaticResource FollowUpStatusProvider}}" />
FollowUpStatusProvider 是一个在应用程序资源级别声明如下的 ObjectDataProvider - 对 MainWindow 和所有 UserControl 均可见:
<ObjectDataProvider x:Key="FollowUpStatusProvider"
MethodName="GetValues" ObjectType="{x:Type DAL:FollowUpStatus}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="DAL:FollowUpStatus"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
它在运行时运行良好。在设计时,设计者可以从 MyUserControl.xaml 渲染它。但我的 MainWindow 抱怨它无法“创建“MyUserControl”类型的实例”。导致 MainWindow 阻塞的代码是对 ComboBox 列中的 ItemsSource 的分配:
... ItemsSource="{Binding Source={StaticResource FollowUpStatusProvider}}" ...
如果我删除此分配,则一切都会按预期工作。
有人可以帮助我理解为什么以及如何解决它吗?
谢谢!
I have a MainWindow.xaml (which consists of a TabControl) and a few UserControls (which are loaded into the TabItems).
One particular UserControl has a WPFToolkit DataGrid with custom columns (not auto-generated). One of these columns is a ComboBox-type column that binds to a property in my model called "Status". I also have an Enum for Status called "FollowUpStatus". This ComboBox column is declared as follows:
<WpfTK:DataGridComboBoxColumn
Header="Status"
SelectedItemBinding="{Binding Status}"
ItemsSource="{Binding Source={StaticResource FollowUpStatusProvider}}" />
The FollowUpStatusProvider is an ObjectDataProvider declared as follows at the application resources level - visible to both MainWindow and all UserControls:
<ObjectDataProvider x:Key="FollowUpStatusProvider"
MethodName="GetValues" ObjectType="{x:Type DAL:FollowUpStatus}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="DAL:FollowUpStatus"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
It all works fine at run-time. At design time, from MyUserControl.xaml, the designer renders it ok. But my MainWindow complains it cannot "create an instance of type 'MyUserControl'". The code that's causing MainWindow to choke is the assignment to ItemsSource in the ComboBox column:
... ItemsSource="{Binding Source={StaticResource FollowUpStatusProvider}}" ...
If I remove this assignment, it all works as expected.
Can somebody help me understand why and how to fix it?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你尝试过吗
Have you tried