IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Windows Presentation Foundation Discussion :

Afficher un composant Winform dans WPF (en passant par un UserControl(WPF))


Sujet :

Windows Presentation Foundation

  1. #1
    Membre à l'essai
    Inscrit en
    Février 2009
    Messages
    21
    Détails du profil
    Informations forums :
    Inscription : Février 2009
    Messages : 21
    Points : 12
    Points
    12
    Par défaut Afficher un composant Winform dans WPF (en passant par un UserControl(WPF))
    Bonjour,

    Je suis entrain de faire réhoster un composant Winform dans une application WPF, pour cela j'ai créé un UserControl (WPF) dont lequel j'ai inséré le composant WinformHost (afin d'afficher mon coposant WinForm dans le UseControl(WPF)). Mais à la compilation, il ne m'apparait que la fenêtre "Window1" c'est à dire que le composant winform ne s'affiche plus.
    Personne a-t-il une idée sur comment je peux l'afficher ?

    SVP aider moi !!!
    Merci d'avance.

  2. #2
    Rédacteur
    Avatar de Thomas Lebrun
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    9 161
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 9 161
    Points : 19 434
    Points
    19 434
    Par défaut
    Heu là, il nous faudrait un peu de code car là, je vois pas le pb

  3. #3
    Membre à l'essai
    Inscrit en
    Février 2009
    Messages
    21
    Détails du profil
    Informations forums :
    Inscription : Février 2009
    Messages : 21
    Points : 12
    Points
    12
    Par défaut
    Citation Envoyé par Thomas Lebrun Voir le message
    Heu là, il nous faudrait un peu de code car là, je vois pas le pb
    Bonjour,

    En fait, je veux réhoster le designer de Workflow dans une application WPF, pour cela j'ai suivi toutes les étapes décrite dans ce lien là : http://ftp-developpez.com/vincentlai...f-designer.pdf
    Vous pouvez donc visiter le code dans ce document là. (Le problème comme je vous ai informé est que le composant Winform(le designer) ne s'affiche plus).

    Une autre question : peux-je suivre ces mêmes étapes pour le réhoster dans une application XBAP ?

    Merci d'avance !
    Cordialement,

  4. #4
    Rédacteur
    Avatar de Thomas Lebrun
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    9 161
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 9 161
    Points : 19 434
    Points
    19 434
    Par défaut
    Tu as donc créer une application WPF qui hoste le designer de WF et lorsque tu hostes cette Window dans du WindowsForms, ca marche plus ?

    Attention, tu ne peux hoster que des Control avec le control WindowsFormsHost, pas des Window.

  5. #5
    Membre à l'essai
    Inscrit en
    Février 2009
    Messages
    21
    Détails du profil
    Informations forums :
    Inscription : Février 2009
    Messages : 21
    Points : 12
    Points
    12
    Par défaut
    Citation Envoyé par Thomas Lebrun Voir le message
    Tu as donc créer une application WPF qui hoste le designer de WF et lorsque tu hostes cette Window dans du WindowsForms, ca marche plus ?

    Attention, tu ne peux hoster que des Control avec le control WindowsFormsHost, pas des Window.
    Salut,

    J'explique encore plus:
    j'ai débuté par créer une application (WPF) nommée "Workflowdesigner.Workflow"
    puis j'ai créé une classe WorkflowLoader héritant de WorkflowDesignerLoader:
    Voici le code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Workflow.ComponentModel.Design;
    namespace WorkflowDesigner.Workflow
    {
    internal class WorkflowLoader : WorkflowDesignerLoader
    {
    public override string FileName
    {
    get {
    return string.Empty;
    }
    }
    public override System.IO.TextReader GetFileReader(string filePath)
    {
    return null;
    }
    public override System.IO.TextWriter GetFileWriter(string filePath)
    {
    return null;
    }
    protected override void
    PerformLoad(System.ComponentModel.Design.Serialization.IDesignerSerializationManager
    serializationManager)
    {
    base.PerformLoad(serializationManager);
    //Obtention du designer associé à ce loader
    IDesignerHost designerHost = (IDesignerHost)GetService(typeof(IDesignerHost));
    if (designerHost == null)
    throw new Exception("Impossible d'obtenir le service de design");
    Activity rootActivity = new SequentialWorkflowActivity();
    designerHost.Container.Add(rootActivity, "root");
    designerHost.Activate();
    }
    }
    }
    ça marche très bien

    puis j'ai créé un UserCOntrol WPF dont j'ai fait un drag&drop du composant "WinformHost" , voici le code XAML de notre UserControl :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    <UserControl x:Class="WorkflowDesigner.Workflow.WorkflowDesigner"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    >
    <WindowsFormsHost x:Name="panel"></WindowsFormsHost>
    </UserControl>
    et finalement le code associé à notre userControl:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    public partial class WorkflowDesigner : UserControl
    {
    private DesignSurface designSurface;
    private WorkflowView workflowView;
    public WorkflowDesigner()
    {
    InitializeComponent();
    }
    public void LoadWorflowDesigner()
    {
    WorkflowLoader loader = new WorkflowLoader();
    this.designSurface = new DesignSurface();
    this.designSurface.BeginLoad(loader);
    //Récupération du designer
    IDesignerHost designerHost = designSurface.GetService(typeof(IDesignerHost)) as IDesignerHost;
    if (designerHost == null)
    return;
    IRootDesigner rootDesigner = designerHost.GetDesigner(designerHost.RootComponent) as IRootDesigner;
    if (rootDesigner == null)
    return;
    this.workflowView = rootDesigner.GetView(ViewTechnology.Default) as WorkflowView;
    this.panel.Child = this.workflowView;
    }
    }
    Mais le "WorkflowView" (qui est notre composant Winform ne s'affiche plus, il ne m'apparait que la page Window(vide)).
    J'arrive pas à comprendre où réside le problème.

    SVP aider moi ,
    Merci d'avance!

  6. #6
    Membre expérimenté
    Profil pro
    Inscrit en
    Juillet 2008
    Messages
    1 562
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 562
    Points : 1 313
    Points
    1 313
    Par défaut
    j'ai deja constate ca si tu met un windowshost et un property grid dedans tu ne vois pas le propertygrid, mais cela fonctionne quand meme
    IKEAS : Finalement je crois que c'est dans ses faiblesses que l'on y trouve a la fois de la force et a la fois de la richesse...
    ----------------------------------------------------
    Si vous avez du taf en wpf & design d'application sympa, contactez moi !!!!
    http://ultimatecorp.eu/wpf/

  7. #7
    Rédacteur
    Avatar de Thomas Lebrun
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    9 161
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 9 161
    Points : 19 434
    Points
    19 434
    Par défaut
    Citation Envoyé par ikeas Voir le message
    j'ai deja constate ca si tu met un windowshost et un property grid dedans tu ne vois pas le propertygrid, mais cela fonctionne quand meme
    Ben si, un WindowsFormsHost et un PropertyGrid, ca marche très bien...

  8. #8
    Rédacteur
    Avatar de Thomas Lebrun
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    9 161
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 9 161
    Points : 19 434
    Points
    19 434
    Par défaut
    @karim: Tu as bien appelée la méthode LoadWorkflowDesigner dans ton code ?

  9. #9
    Membre expérimenté
    Profil pro
    Inscrit en
    Juillet 2008
    Messages
    1 562
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 562
    Points : 1 313
    Points
    1 313
    Par défaut
    Citation Envoyé par Thomas Lebrun Voir le message
    Ben si, un WindowsFormsHost et un PropertyGrid, ca marche très bien...
    certe mais dans l'editeur de vs2008 on ne voit pas le property grid dans le windowshost (mais c'est vrai a l'execution cela marche tres bien
    IKEAS : Finalement je crois que c'est dans ses faiblesses que l'on y trouve a la fois de la force et a la fois de la richesse...
    ----------------------------------------------------
    Si vous avez du taf en wpf & design d'application sympa, contactez moi !!!!
    http://ultimatecorp.eu/wpf/

  10. #10
    Membre à l'essai
    Inscrit en
    Février 2009
    Messages
    21
    Détails du profil
    Informations forums :
    Inscription : Février 2009
    Messages : 21
    Points : 12
    Points
    12
    Par défaut
    Citation Envoyé par Thomas Lebrun Voir le message
    @karim: Tu as bien appelée la méthode LoadWorkflowDesigner dans ton code ?
    Bonjour,
    Merci tout d'abord pour votre réponse, mais, excuser moi j'ai pas bien assimilé le fait de "Mettre un windowshost et un property grid dedans". Plus d'explication svp, qu'est ce que je dois faire exactement ?

    Merci d'avance,
    Cordialement.

  11. #11
    Membre à l'essai
    Inscrit en
    Février 2009
    Messages
    21
    Détails du profil
    Informations forums :
    Inscription : Février 2009
    Messages : 21
    Points : 12
    Points
    12
    Par défaut
    Citation Envoyé par ikeas Voir le message
    certe mais dans l'editeur de vs2008 on ne voit pas le property grid dans le windowshost (mais c'est vrai a l'execution cela marche tres bien
    Bonjour,
    Pouvez vous m'expliquer comment mettre les deux (property grid et windowsHost) ensemble. En fait, je n'ai pas bien compris ce que vous avez cité. Plus d'explication svp ?
    Merci,
    Cordialement,

  12. #12
    Rédacteur
    Avatar de Thomas Lebrun
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    9 161
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 9 161
    Points : 19 434
    Points
    19 434
    Par défaut
    Remplace le code de ton UserContrl WPF par ca:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    public partial class WorkflowDesigner : UserControl
    {
    private DesignSurface designSurface;
    private WorkflowView workflowView;
    public WorkflowDesigner()
    {
    InitializeComponent();
     
    this.LoadWorflowDesigner();
    }
    public void LoadWorflowDesigner()
    {
    WorkflowLoader loader = new WorkflowLoader();
    this.designSurface = new DesignSurface();
    this.designSurface.BeginLoad(loader);
    //Récupération du designer
    IDesignerHost designerHost = designSurface.GetService(typeof(IDesignerHost)) as IDesignerHost;
    if (designerHost == null)
    return;
    IRootDesigner rootDesigner = designerHost.GetDesigner(designerHost.RootComponent) as IRootDesigner;
    if (rootDesigner == null)
    return;
    this.workflowView = rootDesigner.GetView(ViewTechnology.Default) as WorkflowView;
    this.panel.Child = this.workflowView;
    }
    }

  13. #13
    Membre à l'essai
    Inscrit en
    Février 2009
    Messages
    21
    Détails du profil
    Informations forums :
    Inscription : Février 2009
    Messages : 21
    Points : 12
    Points
    12
    Par défaut
    Citation Envoyé par Thomas Lebrun Voir le message
    Remplace le code de ton UserContrl WPF par ca:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    public partial class WorkflowDesigner : UserControl
    {
    private DesignSurface designSurface;
    private WorkflowView workflowView;
    public WorkflowDesigner()
    {
    InitializeComponent();
     
    this.LoadWorflowDesigner();
    }
    public void LoadWorflowDesigner()
    {
    WorkflowLoader loader = new WorkflowLoader();
    this.designSurface = new DesignSurface();
    this.designSurface.BeginLoad(loader);
    //Récupération du designer
    IDesignerHost designerHost = designSurface.GetService(typeof(IDesignerHost)) as IDesignerHost;
    if (designerHost == null)
    return;
    IRootDesigner rootDesigner = designerHost.GetDesigner(designerHost.RootComponent) as IRootDesigner;
    if (rootDesigner == null)
    return;
    this.workflowView = rootDesigner.GetView(ViewTechnology.Default) as WorkflowView;
    this.panel.Child = this.workflowView;
    }
    }
    Bonjour,
    Excuser moi, j'ai remplacé le code de mon UserControl(WPF) mais le problème réside encore (la surface du designer ne s'affiche plus, il ne s'affiche que la fenêtre Window1(toute vide)). Y-a-t-il une solution ?
    Merci,

  14. #14
    Rédacteur
    Avatar de Thomas Lebrun
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    9 161
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 9 161
    Points : 19 434
    Points
    19 434
    Par défaut
    Hum.. tu as une exception qui est déclenchée ? Tu peux nous faire partager ton projet pour qu'on y jette un oeil ?

  15. #15
    Membre expérimenté
    Profil pro
    Inscrit en
    Juillet 2008
    Messages
    1 562
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 562
    Points : 1 313
    Points
    1 313
    Par défaut
    pour le properygrid et windows host voici comment il faut faire
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    <Window x:Class="SimpleViewerGenerator.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:swf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
        xmlns:local="clr-namespace:SimpleViewerGenerator"
        Icon="agences.ico"
        Title="SimpleViewer generator" Height="510.858" Width="759.015" WindowStartupLocation="CenterScreen">
    .....
       <WindowsFormsHost Margin="6,6,6,0" Name="windowsFormsHost1">
                                <swf:PropertyGrid x:Name="propertyGrid"/>
                            </WindowsFormsHost>
    ne pas oublier d'ajouter l'assembly system.windows.form au referencess
    IKEAS : Finalement je crois que c'est dans ses faiblesses que l'on y trouve a la fois de la force et a la fois de la richesse...
    ----------------------------------------------------
    Si vous avez du taf en wpf & design d'application sympa, contactez moi !!!!
    http://ultimatecorp.eu/wpf/

  16. #16
    Membre à l'essai
    Inscrit en
    Février 2009
    Messages
    21
    Détails du profil
    Informations forums :
    Inscription : Février 2009
    Messages : 21
    Points : 12
    Points
    12
    Par défaut
    Citation Envoyé par Thomas Lebrun Voir le message
    Hum.. tu as une exception qui est déclenchée ? Tu peux nous faire partager ton projet pour qu'on y jette un oeil ?
    Bonjour,
    Voila donc mon code source complet :
    La classe WorkflowLoader:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    internal class WorkflowLoader : WorkflowDesignerLoader
        {
            public override string FileName
            {
                get
                {
                    return string.Empty;
                }
            }
            public override System.IO.TextReader GetFileReader(string filePath)
            {
                return null;
            }
            public override System.IO.TextWriter GetFileWriter(string filePath)
            {
                return null;
            }
     
            protected override void
    PerformLoad(System.ComponentModel.Design.Serialization.IDesignerSerializationManager
    serializationManager)
            {
                base.PerformLoad(serializationManager);
                //Obtention du designer associé à ce loader
                IDesignerHost designerHost = (IDesignerHost)GetService(typeof(IDesignerHost));
                if (designerHost == null)
                    throw new Exception("Impossible d'obtenir le service de design");
                Activity rootActivity = new SequentialWorkflowActivity();
                designerHost.Container.Add(rootActivity, "root");
                designerHost.Activate();
            }
        }
    La page WorkflowDesigner.Xaml :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    <UserControl x:Class="Workflowdesigner.Workflow.WorkflowDesigner"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     
     
        Height="300" Width="300">
     
        <WindowsFormsHost Margin="6,6,6,0"  x:Name="panel" >
     
     
        </WindowsFormsHost>
     
    </UserControl>

    WorkflowDesigner.xaml.cs

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
     public partial class WorkflowDesigner : UserControl
        {
            private DesignSurface designSurface;
            private WorkflowView workflowView;
     
            public WorkflowDesigner()
            {
                InitializeComponent();
     
                this.LoadWorflowDesigner();
            }
     
            public void LoadWorflowDesigner()
            {
                WorkflowLoader loader = new WorkflowLoader();
                this.designSurface = new DesignSurface();
                this.designSurface.BeginLoad(loader);
                //Récupération du designer
                IDesignerHost designerHost = designSurface.GetService(typeof(IDesignerHost)) as IDesignerHost;
                if (designerHost == null)
                    return;
                IRootDesigner rootDesigner = designerHost.GetDesigner(designerHost.RootComponent) as IRootDesigner;
                if (rootDesigner == null)
                    return;
                this.workflowView = rootDesigner.GetView(ViewTechnology.Default) as WorkflowView;
                this.panel.Child = this.workflowView;
            }
        }
    Merci,

  17. #17
    Rédacteur
    Avatar de Thomas Lebrun
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    9 161
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 9 161
    Points : 19 434
    Points
    19 434
    Par défaut
    Et à propos de l'exception... ?

  18. #18
    Membre à l'essai
    Inscrit en
    Février 2009
    Messages
    21
    Détails du profil
    Informations forums :
    Inscription : Février 2009
    Messages : 21
    Points : 12
    Points
    12
    Par défaut
    Citation Envoyé par Thomas Lebrun Voir le message
    Et à propos de l'exception... ?
    Bonjour,
    En fait, je n'ai pas compris de quelle exception vous parlez, pouvez-vous m'expliquer d'avantage?
    Aider moi SVP : je suis perdu et je ne peux plus avancer sans résoudre ce problème.
    Merci d'avance,
    à + ,

Discussions similaires

  1. Afficher un composant Sharepoint dans une page HTML
    Par romualdb dans le forum Balisage (X)HTML et validation W3C
    Réponses: 0
    Dernier message: 05/02/2014, 10h52
  2. Réponses: 0
    Dernier message: 15/12/2011, 20h09
  3. Composants Winforms dans WPF
    Par Invité dans le forum Windows Presentation Foundation
    Réponses: 1
    Dernier message: 23/08/2011, 17h40
  4. Afficher une info bulle dans un composant AWT
    Par Marius_94 dans le forum AWT/Swing
    Réponses: 8
    Dernier message: 13/07/2006, 09h56
  5. Pb pour afficher des composants dans la palette
    Par Captain_JS dans le forum C++Builder
    Réponses: 1
    Dernier message: 12/07/2005, 18h35

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo