【发布时间】:2012-08-27 01:02:16
【问题描述】:
我正在尝试在一个简单的 WPF 应用程序中使用一个使用 winforms 的 MonthCalendar 控件。我发现通过使用 WindowsFormsHost,winforms 控件可以在 wpf 应用程序中使用。它适用于 winforms 的内置控件,但是当我尝试实例化此控件 MonthCalendar 的对象时,我收到错误消息“无法实例化 MonthCalendar 的对象”。
关于为什么会发生这种情况以及如何克服这个问题的任何建议? MonthCalendar 的源代码位于http://www.codeproject.com/Articles/10840/Another-Month-Calendar?msg=2298161#xx2298161xx
我在 xaml 中实例化它:
<Window x:Class="MonthCalendarTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
xmlns:pc="clr-namespace:Pabo.Calendar"
Title="MainWindow" Height="350" Width="525">
<Grid Height="65" Width="280">
<WindowsFormsHost Margin="0,0,12,12" Height="100">
<pc:MonthCalendar></pc:MonthCalendar>
</WindowsFormsHost>
</Grid>
【问题讨论】:
-
你是如何实例化的,在代码中还是在 xaml 中?如果是它的代码,也许您可以将该代码添加到您的问题中。
-
对不起,我忘了说,我在 xaml 中实例化它,请参阅我编辑的帖子。
-
MonthCalendar有无参数构造函数吗? -
是的,它确实有一个无参数的构造函数。