2013-01-24 48 views
0

我試圖在我的WPF UserControl中放置一個Winforms面板,使用下面的代碼;XAML嵌入式WinForms面板不支持直接內容?

<WindowsFormsHost Grid.Row="3"> 
    <WinForms:Panel> 
     <WinForms:TableLayoutPanel x:Name="myLayoutPanel" /> 
    </WinForms:Panel> 
</WindowsFormsHost> 

錯誤:

The type 'Panel' does not support direct content.

我然後會再初始化中的C#代碼TableLayoutPanel面板。任何想法我可以如何解決這個錯誤?

回答

0

Windows.Forms Panel Container被稱爲Controls。你應該可以通過這樣做來添加它:如果是我,我只需創建一個Winforms UserControl並將其添加到WinFormsHost中。

<WindowsFormsHost Height="100" HorizontalAlignment="Left" Margin="10,108,0,0" Name="windowsFormsHost1" VerticalAlignment="Top" Width="200"> 
    <WinForms:Panel BackColor="Red" Dock="Fill"> 
     <WinForms:Panel.Controls> 
      <WinForms:TableLayoutPanel x:Name="myLayoutPanel"/> 
     </WinForms:Panel.Controls> 
    </WinForms:Panel> 
</WindowsFormsHost> 
相關問題