2017-12-14 27 views
1

먼저 문서 기반 VSTO 프로젝트입니다. 따라서 이러한 추가 기능 VSTO 연습은 실제로 작동하지 않습니다.VSTO가 ActionPane 및 WPF usercontrol/ElementHost에 변수를 전달하는 경우

ActionPaneControl을 만들 수 있었고 ElementHost를 사용하여 WPF usercontrol을 추가 할 수있었습니다. 코드는 다음과 같은를 시작합니다 :

ActionsPaneControl1 apc = new ActionsPaneControl1();    
Globals.ThisWorkbook.ActionsPane.Controls.Add(apc); 
Globals.ThisWorkbook.ActionsPane.Visible = true; 

을하지만, 나는 WPF의 UserControl을에 매개 변수를 전달하려합니다. 그러면이 코드에 WPF usercontrol을 나타내는 코드가 없다는 것을 알게됩니다. 내 생각 엔 ElementHost와 관련이 있다는 것입니다.

아무도 도와 줄 수 있습니까?

당신에게

편집 감사합니다 여기 당신은 ElementHost을 통해 WPF UserControl을 액세스 할 수 ActionPaneControl1 클래스

partial class ActionsPaneControl1 
{ 
private System.ComponentModel.IContainer components = null; 
..... 
private void InitializeComponent() 
    { 
     this.elementHost1 = new 
     System.Windows.Forms.Integration.ElementHost(); 
     this.elementHost2 = new 
     System.Windows.Forms.Integration.ElementHost(); 
     this.ucWPF1 = new SWAPAEMonthlyReview.ucWPF(); 
     ..... 
    } 

답변

0

입니다.

public ActionsPaneControl1() 
{ 
    InitializeComponent(); 
    if (elementHost1.Child != null) 
    { 
    var wpfControl = elementHost1.Child as WpfUserControlClassName; 
    } 
} 
+0

크리스. 감사합니다. 내 편집 게시물을 참조하십시오. 코드를 어디에 넣어야합니까? – Heisenberg

+0

'ActionsPaneControl1'의 생성자입니다. – Chris

+0

어 .... ActionPaneControl1에서 이미 동일한 매개 변수 유형의 '.ctor'라는 ProjectName 멤버를 정의했다고 말하고 있습니다 ... 부분 클래스와 관련이 있다고 생각합니까? – Heisenberg

1

내 대답에 대한 해결책을 찾은 Chris의 답변에 감사드립니다. 다음은 코드입니다. 문자열 x를 원하는 것으로 변경할 수 있습니다.

WPF에서 ActionPaneControl1.cs이

public ucWPF(string x) 
    { 
     InitializeComponent(); 
     //do whatever with x 
    } 

를 넣어하여 ActionPaneControl1.Designer.cs에 다음을 편집하려면이

partial class ActionsPaneControl1 : UserControl 
{ 
    public ActionsPaneControl1(string x) 
    { 
     InitializeComponent(x); 

    } 
} 

와 마지막 단계입니다 넣어

public void InitializeComponent(string x) 
    { 
     ............ 
     this.ucWPF1 = new SWAPAEMonthlyReview.ucWPF(x);  
     ....... 
    } 
+0

* .Designer.cs를 직접 수정해서는 안되며, 정확히 말하면 바로 주석이 있어야합니다. 디자이너와 UI를 수정하면 다시 생성됩니다. 어쨌든'InitializeComponent'에 패스 할 필요는 없으며,'ActionsPaneControl1.cs'에서 바로 액세스 할 수 있습니다. 내 대답에 대한 오해의 뿌리는 당신이 컨트롤을 오른쪽 클릭하여'코드보기 '를 할 수 있다는 것을 깨닫지 못했다는 것입니다. 거기에 모든 사용자 정의 코드를 수행해야합니다. – Chris