I’m trying to use a MonthCalendar Control that uses winforms, in a simple WPF application. I found out that by using a WindowsFormsHost, winforms controls can be used in wpf apps. It worked for the built-in controls of winforms, but when I try to instantiate an object of this control MonthCalendar, I get an error saying “Cannot instantiate an object of MonthCalendar”.
Any suggestions as to why this is happening and how to overcome this?
The source code for MonthCalendar is available at http://www.codeproject.com/Articles/10840/Another-Month-Calendar?msg=2298161#xx2298161xx
Im instantiating it in 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>
I can get it to work by following these steps:
add references to System.Windows.Forms and WindowsFormIntegration
download MonthCalendar from:
http://www.codeproject.com/KB/selection/MonthCalendar/MonthCalendar_src_vs2005.zip
So what are you doing differently?
Did you keep the MonthCalendar in it’s own project?
What OS platform are you running on ?