Sugerir tradução
 
Outras sugestões:

progress indicator
Sem sugestões.
Clique para classificar e enviar comentários
MSDN
Biblioteca MSDN
.NET Framework 3.5
.NET Framework
 Demonstra Passo a passo: Que hosped...

  Ativar exibição de largura de banda baixa
Exibir Conteúdo: Lado a LadoExibir Conteúdo: Lado a Lado
Este conteúdo foi traduzido automaticamente e pode ser editado pelos membros da comunidade. Para melhorar a qualidade da tradução, clique no link Editar associado à frase que deseja modificar.
Windows Presentation Foundation
Walkthrough: Hosting a Windows Presentation Foundation Composite Control in Windows Forms

This walkthrough demonstrates how you can create a WPF composite control and host it in Windows Forms controls and forms by using the ElementHost control.

In this walkthrough, you will implement a WPF UserControl that contains two child controls. The UserControl displays a three-dimensional (3-D) cone. Rendering 3-D objects is much easier with the WPF than with Windows Forms. Therefore, it makes sense to host a WPF UserControl class to create 3-D graphics in Windows Forms.

Tasks illustrated in this walkthrough include:

For a complete code listing of the tasks illustrated in this walkthrough, see Hosting a Windows Presentation Foundation Composite Control in Windows Forms Sample.

Note   The dialog boxes and menu commands you see might differ from those described in Help, depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

You need the following components to complete this walkthrough:

  • Visual Studio 2008.

To create the UserControl

  1. Create a WPF User Control Library project named HostingWpfUserControlInWf.

  2. Open UserControl1.xaml in the WPF Designer.

  3. Replace the generated code with the following code.

    This code defines a System.Windows.Controls..::.UserControl that contains two child controls. The first child control is a System.Windows.Controls..::.Label control; the second is a Viewport3D control that displays a 3-D cone.

To create the host project

  1. Add a Windows application project named WpfUserControlHost to the solution. For more information, see Add New Project Dialog Box.

  2. In Solution Explorer, add a reference to the WindowsFormsIntegration assembly, which is named WindowsFormsIntegration.dll.

  3. Add references to the following WPF assemblies:

    • PresentationCore

    • PresentationFramework

    • WindowsBase

  4. Add a reference to the HostingWpfUserControlInWf project.

  5. In Solution Explorer, set the WpfUserControlHost project to be the startup project.

To host the UserControl

  1. In the Windows Forms Designer, open Form1.

  2. In the Properties window, click Events, and then double-click the Load event to create an event handler.

    The Code Editor opens to the newly generated Form1_Load event handler.

  3. Replace the code in Form1.cs with the following code.

    The Form1_Load event handler creates an instance of UserControl1 and adds itto the ElementHost control's collection of child controls. The ElementHost control is added to the form's collection of child controls.

    Visual Basic
    Imports System
    Imports System.Collections.Generic
    Imports System.ComponentModel
    Imports System.Data
    Imports System.Drawing
    Imports System.Text
    Imports System.Windows.Forms
    
    Imports System.Windows.Forms.Integration
    
    Public Class Form1
        Inherits Form
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ' Create the ElementHost control for hosting the
            ' WPF UserControl.
            Dim host As New ElementHost()
            host.Dock = DockStyle.Fill
    
            ' Create the WPF UserControl.
            Dim uc As New HostingWpfUserControlInWf.UserControl1()
    
            ' Assign the WPF UserControl to the ElementHost control's
            ' Child property.
            host.Child = uc
    
            ' Add the ElementHost control to the form's
            ' collection of child controls.
            Me.Controls.Add(host)
        End Sub
    
    End Class
    
    
  4. Press F5 to build and run the application.

Windows Presentation Foundation
Demonstra Passo a passo: Que hospedam um Windows Presentation Foundation composto Controlarar no Windows Forms

Essa explicação passo a passo demonstra como você pode criar um controle composto WPF e hospedá-lo em formulários e controles Windows Forms ao usar o controle ElementHost.

Nesta explicação passo a passo, você implementará um WPF UserControl que contém dois controles filhos. O UserControl exibe um cone tridimensional (3D). Renderizar objetos 3D é muito mais fácil com o WPF do que com Windows Forms. Portanto, faz sentido hospedar uma classe WPF UserControl para criar gráficos 3D em Windows Forms.

Tarefas ilustradas nesta explicação passo a passo incluem:

For a complete code listing of the tasks illustrated in this walkthrough, see Que hospedam um Windows Presentation Foundation composto Controlarar no Windows Forms Exemplo.

Observação As caixas de diálogo e comandos de menu você vê podem diferir daqueles descritos na ajuda dependendo de suas configurações ativas ou versão. Para alterar estas configurações, escolha Importar e Exportar Configurações no menu de Ferramentas. Para obter mais informações, consulte Configurações do Visual Studio.

Para completar este passo a passo, são necessários os seguintes componentes:

  • Visual Studio 2008.

Para criar o UserControl

  1. Criar um projeto Biblioteca de Controle de Usuário WPF chamado HostingWpfUserControlInWf.

  2. Abra UserControl1.xaml no WPF Designer.

  3. Substitua o código gerado pelo seguinte código.

    Este código define um System.Windows.Controls..::.UserControl contendo dois controles filho. O primeiro controle filho é um controle System.Windows.Controls..::.Label; a segunda é um controle Viewport3D que exibe um cone 3D.

To create the host project

  1. Adicione um projeto de aplicativos do Windows chamado WpfUserControlHost à solução. For more information, see Caixa de Diálogo Add New Project.

  2. No Solution Explorer, acrescente uma referência ao assembly WindowsFormsIntegration, que é chamado WindowsFormsIntegration.dll.

  3. Adicione referências para os seguintes conjuntos de módulos (assemblies) WPF:

    • PresentationCore

    • PresentationFramework

    • WindowsBase

  4. Adicione uma referência para o projeto HostingWpfUserControlInWf.

  5. No Gerenciador de Soluções, defina o projeto WpfUserControlHost como o projeto de inicialização.

Para hospedar o UserControl

  1. No Windows Forms Designer, abra Form1.

  2. Na janela Propriedades, clique em Events e em seguida, clique duas vezes no evento Load para criar um tratador de eventos.

    O Editor de Código abre o tratador de eventos Form1_Load recém-gerado.

  3. Substitua o código em Form1.cs com o seguinte código.

    The Form1_Load event handler creates an instance of UserControl1 and adds itto the ElementHost control's collection of child controls. O controle ElementHost é adicionado à coleção de controles filho do formulário.

    Visual Basic
    Imports System
    Imports System.Collections.Generic
    Imports System.ComponentModel
    Imports System.Data
    Imports System.Drawing
    Imports System.Text
    Imports System.Windows.Forms
    
    Imports System.Windows.Forms.Integration
    
    Public Class Form1
        Inherits Form
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ' Create the ElementHost control for hosting the
            ' WPF UserControl.
            Dim host As New ElementHost()
            host.Dock = DockStyle.Fill
    
            ' Create the WPF UserControl.
            Dim uc As New HostingWpfUserControlInWf.UserControl1()
    
            ' Assign the WPF UserControl to the ElementHost control's
            ' Child property.
            host.Child = uc
    
            ' Add the ElementHost control to the form's
            ' collection of child controls.
            Me.Controls.Add(host)
        End Sub
    
    End Class
    
    
  4. Pressione F5 para criar e executar o aplicativo.

Conteúdo da Comunidade   O que é Conteúdo da Comunidade?
Adicionar novo conteúdo RSS  Anotações
Processing
© 2009 Microsoft Corporation. Todos os direitos reservados. Termos de Uso  |  Marcas Comerciais  |  Política de Privacidade
Page view tracker