开发者

WPF - Help with DataGrid's ComboBox column in UserControl

开发者 https://www.devze.com 2022-12-08 23:15 出处:网络
I have a MainWindow.xaml (which consists of a TabControl) and a few UserControls (which are loaded into the TabItems).

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 a开发者_如何学Pythonuto-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!


Have you tried

... ItemsSource="{StaticResource FollowUpStatusProvider}"
0

精彩评论

暂无评论...
验证码 换一张
取 消