none
WinFormsControlLibrary & WPF control RRS feed

  • 問題

  • 我最近在研究Kinect SDK,我想加入一個WinFormsControlLibrary(以XNA render的控制項,已完成)到SkeletalViewer of Kinect Sample,但是這個sample是.NET Framework 4 Client Profile/Windows Application,只能支援wpf controls,我做好的XNA WinFormsControl可以加入tool box但是是灰色的不可以拉到skeletalviewer,請問一下是有人知道如何解決嗎?

    akira32 編程之家 Yahoo http://tw.myblog.yahoo.com/akira32-akira32
    2011年6月23日 下午 01:10

解答

  • Dear akira32,

     

             假設,你的Windows Form Library為WindowsFormControlLibrary1,先在WPF 中添加對其的Reference,

       然後於WPF 頁面中放入WindowsFormsHost控制項, 他是灰色的.

       接著於WPF 頁面中引入Namespace,如下所示:

    <Window x:Class="SkeletalViewer.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:wf="clr-namespace:WindowsFormsControlLibrary1;assembly=WindowsFormsControlLibrary1"
        Title="MainWindow" Icon="SkeletalViewer.ico" ResizeMode="NoResize" SizeToContent="WidthAndHeight" WindowStartupLocation="CenterScreen"
        Loaded="Window_Loaded" Closed="Window_Closed" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="902">
      <StackPanel>
        <StackPanel Orientation="Horizontal">
          <StackPanel>
            <TextBox FontSize="18" Focusable="False" BorderThickness="0" Text="Depth Stream" HorizontalAlignment="Center"/>
            <Image Width="400" Height="300" Name="depth" Margin="10 0 10 10"/>
          </StackPanel>
          <StackPanel>
            <TextBox FontSize="18" Focusable="False" BorderThickness="0" Text="Skeleton (rendered if full body fits in frame)" HorizontalAlignment="Center"/>
            <Canvas Width="400" Height="300" Name="skeleton" Margin="10 0 10 10" Background="Black" ClipToBounds="True"/>
          </StackPanel>
        </StackPanel>
        <StackPanel Orientation="Horizontal">
          <Viewbox Width="400" Margin="10" Stretch="None" VerticalAlignment="Stretch">
            <TextBox FontSize="72" Name="frameRate" Margin="10" Focusable="False" BorderThickness="0" Text="0 fps" TextAlignment="Right" HorizontalAlignment="Center" VerticalAlignment="Center" Width="250"/>
          </Viewbox>
          <StackPanel>
            <TextBox FontSize="18" Focusable="False" BorderThickness="0" Text="Color Video Stream" HorizontalAlignment="Center" Name="VideoCaption" />
            <Image Width="400" Height="300" Name="video" Margin="10 0 10 10"/>
          </StackPanel>
        </StackPanel>
        <WindowsFormsHost Height="195" Name="windowsFormsHost1" Width="434">
          <wf:UserControl1/>
        </WindowsFormsHost>
      </StackPanel>
    </Window>
    
    


    MVP 2010 - Visual Developer ASP/ASP.NET My Blog: http://www.dotblogs.com.tw/code6421/
    • 已標示為解答 akira32 2011年6月25日 上午 02:33
    2011年6月23日 下午 04:40

所有回覆

  • Dear akira32,

     

             假設,你的Windows Form Library為WindowsFormControlLibrary1,先在WPF 中添加對其的Reference,

       然後於WPF 頁面中放入WindowsFormsHost控制項, 他是灰色的.

       接著於WPF 頁面中引入Namespace,如下所示:

    <Window x:Class="SkeletalViewer.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:wf="clr-namespace:WindowsFormsControlLibrary1;assembly=WindowsFormsControlLibrary1"
        Title="MainWindow" Icon="SkeletalViewer.ico" ResizeMode="NoResize" SizeToContent="WidthAndHeight" WindowStartupLocation="CenterScreen"
        Loaded="Window_Loaded" Closed="Window_Closed" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="902">
      <StackPanel>
        <StackPanel Orientation="Horizontal">
          <StackPanel>
            <TextBox FontSize="18" Focusable="False" BorderThickness="0" Text="Depth Stream" HorizontalAlignment="Center"/>
            <Image Width="400" Height="300" Name="depth" Margin="10 0 10 10"/>
          </StackPanel>
          <StackPanel>
            <TextBox FontSize="18" Focusable="False" BorderThickness="0" Text="Skeleton (rendered if full body fits in frame)" HorizontalAlignment="Center"/>
            <Canvas Width="400" Height="300" Name="skeleton" Margin="10 0 10 10" Background="Black" ClipToBounds="True"/>
          </StackPanel>
        </StackPanel>
        <StackPanel Orientation="Horizontal">
          <Viewbox Width="400" Margin="10" Stretch="None" VerticalAlignment="Stretch">
            <TextBox FontSize="72" Name="frameRate" Margin="10" Focusable="False" BorderThickness="0" Text="0 fps" TextAlignment="Right" HorizontalAlignment="Center" VerticalAlignment="Center" Width="250"/>
          </Viewbox>
          <StackPanel>
            <TextBox FontSize="18" Focusable="False" BorderThickness="0" Text="Color Video Stream" HorizontalAlignment="Center" Name="VideoCaption" />
            <Image Width="400" Height="300" Name="video" Margin="10 0 10 10"/>
          </StackPanel>
        </StackPanel>
        <WindowsFormsHost Height="195" Name="windowsFormsHost1" Width="434">
          <wf:UserControl1/>
        </WindowsFormsHost>
      </StackPanel>
    </Window>
    
    


    MVP 2010 - Visual Developer ASP/ASP.NET My Blog: http://www.dotblogs.com.tw/code6421/
    • 已標示為解答 akira32 2011年6月25日 上午 02:33
    2011年6月23日 下午 04:40
  • XNAWinFormControl=new XNAWinFormControl();

    windowsFormsHost1.Child = XNAWinFormControl;

    可以了多謝.


    akira32 編程之家 Yahoo http://tw.myblog.yahoo.com/akira32-akira32
    2011年6月25日 上午 02:33