Tuesday, May 10, 2011

Alvas.Audio and WPF

To use Windows Forms controls in Windows Presentation Foundation(WPF) applications you need:
  • To create RecorderEx or PlayerEx use a constructor with a parameter isConsole = true. Example: new RecorderEx (true); or PlayerEx (true);
  • Add reference to WindowsFormsIntegration assembly (in WindowsFormsIntegration.dll) to your project.
  • Add reference to System.Windows.Forms assembly (in System.Windows.Forms.dll) to your project.
  • In the Window element, add the following namespace mapping

    xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"


    in Window1.xaml. The wf namespace mapping establishes a reference to the assembly that contains the Windows Forms control.
  • Place WindowsFormsHost container with our control. For example, PropertyGrid

    <WindowsFormsHost Grid.Row="1" Grid.Column="0" >

        <wf:PropertyGrid x:Name="pgMain"/>

    </WindowsFormsHost>


  • You can add control into WindowsFormsHost container in run-time:
    • Place empty WindowsFormsHost container to our Window1.xaml

      <WindowsFormsHost Name="wfh" Grid.Row="1" Grid.Column="1" ></WindowsFormsHost>


    • and create WaveformVisualizer (from Alvas.Audio.dll) control and place it to WindowsFormsHost container in run-time

      private void InitWaveformVisualizer()

      {

          wfv = new WaveformVisualizer();

          wfh.Child = wfv;

      }

      private WaveformVisualizer wfv;


Full-featured examples in C# and VB.Net (WpfCs and WpfVb projects) you can see in Alvas.Audio Demos

No comments:

Post a Comment