Windows フォームで作成された従来のライブラリがあります。このライブラリを既存の WPF アプリケーションで使用したいと考えています。このリンクによると、それは可能です。これをやろうとした人はいますか?私たちが探す必要がある警告は何ですか?何かアドバイス?
ありがとう!
この件に関しては、多くの情報源が利用可能です。簡単な Google 検索から返されたいくつかを次に示します。
最初のリンクは非常に簡単で管理しやすいので説明します。実際にはそれほど多くのコードはありません。
最初に、次のアセンブリへの参照を追加する必要があります。
次に、グリッドを作成します (この場合は Grid1 という名前)。
コードビハインドは次のとおりです。
private void Window_Loaded(object sender, RoutedEventArgs e)
{
// Create the interop host control.
System.Windows.Forms.Integration.WindowsFormsHost host =
new System.Windows.Forms.Integration.WindowsFormsHost();
// Create the MaskedTextBox control.
MaskedTextBox mtbDate = new MaskedTextBox("00/00/0000");
// Assign the MaskedTextBox control as the host control's child.
host.Child = mtbDate;
// Add the interop host control to the Grid
// control's collection of child controls.
this.grid1.Children.Add(host);
}
実行しているのは、 をインスタンス化し、WindowsFormsHost
mtbDate という名前の子コントロールを追加することだけです。独自のコントロールをインスタンス化し、代わりに同じメソッドを使用して追加します。次に、Win Forms で通常行うように操作します。
次に、クラスの先頭に using を追加します。
using System.Windows.Forms;
それが役立つことを願っています。