Wpf çıkalı birkaç yıl olmasına rağmen hala bir html editör bulunmamaktadır. Neyseki WindowsFormsHost classı yardımıyla Windows Forms Controllerini WPF’te de kullanabiliyoruz.
Windows Forms için açık kaynak kodlu bir html editör buldum www.windowsclient.net te. Başarılı bir derlemenin ardından WPF’e entegre işlemine başlayalım. WPF uygulamamızın referanslarına WindowsFormsIntegration.dll, System.Windows.Forms.dll ve daha önce indirip derlediğimiz HTML editörünün dll kütüphanelerini ekliyoruz.
İşte başlıyoruz bakın ne kadar kolay.
Even WPF has been released for a few years still there is no html editor. Happily, we can use Windows Forms Controls in WPF via WindowsFormsHost class.
I found an open source html editor for Windows Forms from www.windowsclient.net. Let’s start to create an example in WPF after a succesful compilation. Firstly, add these libraries to your WPF application references: WindowsFormsIntegration.dll, System.Windows.Forms.dll and HTML Editor’s libraries which we’ve downloaded already and compiled.
Here we go to start and see how it’s so easy.
public partial class Window1 : Window
{
WindowsFormsHost wfh = new WindowsFormsHost(); // Windows Form Controllerini WPF içerisinde barındırmamız sağlayacak.
//Provide to host Windows Forms Controllers
Microsoft.ConsultingServices.HtmlEditor.HtmlEditorControl htmlEditor; // WinForm HTML editör.
// The HTML Editor.
public Window1()
{
InitializeComponent();
Loaded += new RoutedEventHandler(Window1_Loaded);
}
void Window1_Loaded(object sender, RoutedEventArgs e)
{
htmlEditor = new Microsoft.ConsultingServices.HtmlEditor.HtmlEditorControl();
wfh.Child = htmlEditor; // barındıralacak controllü setliyoruz. // we are setting the control which is going to host inside the Windows Forms Host.
grd.Children.Add(wfh); // ve son olarak da Grid'imize Windows Form Host'u ekleyoruz. // And finally we add the Windows Form Host to our Grid.
}
}
Happy Coding
