2011-11-29 4 views
6

私は自分のWindowsFormアプリケーションにnovoLoginという新しいWPFウィンドウを追加しました。WindowsFormのWPFウィンドウを開くAPP

追加した後、system.xamlリファレンスを追加しました。

今、私は既存のwindowsFormからこの新しいウィンドウを開こうとしています。

novoLogin nl = new novoLogin(); 
nl.show(); 

コンパイラはこのエラーを与えている:

Error 1 'WindowsFormsApplication1.novoLogin' does not contain a definition for 'show' and no extension method 'show' accepting a first argument of type 'WindowsFormsApplication1.novoLogin' could be found (are you missing a using directive or an assembly reference?)

+4

を表示するようにしたいウィンドウです:

private void button1_Click(object sender, EventArgs e) { if (System.Windows.Application.Current == null) { app = new WPFTest.App() { ShutdownMode = ShutdownMode.OnExplicitShutdown }; app.InitializeComponent(); } else { app = (WPFTest.App)System.Windows.Application.Current; app.MainWindow = new WPFTest.YourWindow(); System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(app.MainWindow); app.MainWindow.Show(); } } 

注:私たちは持っているボタンイベントでは? – madd0

答えて

22

このbrief articleは、あなたがこれを実現する方法について説明します。

WinFormsのプログラムからWPFウィンドウを開く必要にあなた自身を見つけた場合、これはそれを行うための一つの方法ですが(私の作品):

  1. タイプの新しいプロジェクトを作成/追加WPF Custom Control Library
  2. 作成し、あなたのWinFormsアプリからWPFウィンドウ
  3. であなたのことを行うタイプWindow (WPF)

  4. の新しい項目の追加やWPFウィンドウ

    を開きます
+0

@Purplegoldfish:あなたがコードを追加したのを見ました(なぜあなたが改訂版でこれをしたのか)。ありがとう、私は将来の答えのためにこれを念頭に置いておくことができます! :) – Abbas

3

はこれに見てください:http://www.mobilemotion.eu/?p=1537&lang=en

概要:

Open the project’s manifest file (the one with the .csproj or .vbproj extension) in any text editor. The top node usually contains several tags, one for each build configuration and a global one. In the global node (the one without Condition attribute), search for the sub-node or create one if it does not exist. This node should contain two GUIDs: FAE04EC0-301F-11D3-BF4B-00C04F79EFBC, which stands for a C# project, and 60dc8134-eba5-43b8-bcc9-bb4bc16c2548 which stands for WPF. The full line should look as follows:

<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

(If you’re interested in details, codeproject holds a complete list of potential project GUIDs: http://www.codeproject.com/Reference/720512/List-of-Visual-Studio-Project-Type-GUIDs)

Reload the project in Visual Studio, and open the Add New Item wizard.

Since the project is now officially classified as WPF project, this wizard should now contain the WPF window option. By the way, since there is no WinForms project GUID that could be overwritten, this approach does not harm the existing project components.

私はVB.NETのプロジェクトのために、このアプローチを試してみましたが、それは動作します!私が見せたかったあなたは{F184B08F-C81C-45F6-A57F-5ABD9991F28F}に{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}からGUIDを代入ライン上で編集する必要が明らかにVB.NETを使用して

0

ウインドウフォームのwpfフォームにいくつかのリソースの問題がありました...

(私はリソースを使っているためです)。最後に、私は私のWindowsFormのプロジェクトにこのコードを使用:これはグローバルである理由

WPFTest.App app; 

まず、このようなあなたのアプリクラスのグローバルインスタンスを作成しますか?

このクラスはシングルトンであり、あなたは今、たとえばあなたは、WPFフォームを表示するには、ボタンイベントを持っている同じアプリケーションドメインに

の複数のインスタンスを作成することはできませんので。あなたは、C#は右、大文字と小文字が区別されることを知っていますWPFTestプロジェクトとYourWindow(の名前)あなたは

関連する問題