locked
Accessing properties of Hosted WPF control in a WinForms app. RRS feed

  • Question

  • Hi,

    I’m just begining to look at WPF so sorry if this seems a naive question.

    I'm looking at hosting WPF user controls in Window Forms.  I do my development work in VS 2010 and I've worked though a couple of examples for doing this without any problems.

    However, if I create my WPF controls in a separate project snd then reference that project from my Windows Forms App project I can no longer directly access the properties of the components within my WPF controls.

    For example:  If my WPF control is created in the local project and If I have a Label in my WPF control defined as follows:-

    <Label Name=”lblFred” Height=”30” Width=”200” Content=”This is Fred” /Label>
    

    I can access it like this..   

    this.wpfuc1.lblFred.Content = “Now its Wilma” ;
    

    But  If I take the same WPF control and relocate it into a WPFControlLibrary project (and set up the reference to it from my Windows Forms App) I can no longer use this.wpfUc1.lblFred to access the content.

    I'm assuming this is something to do with access modifiers, but I'm not sure where to look to change them... or even if its possible to so.  Can anyone enlighten me?

    My only other alternative is to set up public properties in the WPF control that expose the items I want to manipulate 

    public string FredLabel{
      get{return this.lblFred.Content.ToString();}
      set{ this.lblFred.Content = value; }
    }
    
    But I'm sure this shouldn't be necessary... should it?

     

     


    Philip Cole
    Friday, August 20, 2010 3:05 PM

Answers

All replies

  • Hi

    Plz follow the link, you might get some idea

    http://msdn.microsoft.com/en-us/library/ms742215.aspx

    Regards

    Zee

    • Marked as answer by Phil R. Cole Monday, August 23, 2010 7:47 AM
    Friday, August 20, 2010 6:56 PM
  • Hmmm....  It doesn't give a complete explanation, but it implies that I do need to expose the parts of my control that I want  to manipulate as public properties if I want to get at them from the hosting winforms app.  So at least I know I was heading in the right direction.

    Thanks Zee.


    Philip Cole
    Monday, August 23, 2010 7:51 AM