Windows Vista Forums

Data Binding in user control

  1. #1


    Griff Guest

    Data Binding in user control

    I can do this
    - create a Window
    - define a Dependency property in the code behind the Window
    - bind this property it to the content of some standard control placed in
    the Window
    (Eg a TextBlock which displays a string set in the code behind)
    So far so good.

    But when I
    - create a custom control (MyControl.xaml & MyControl.xaml.cs)
    - define dependency properties in the code behind the control
    - use those properties in the markup for the control to define its appearance
    - deploy the control in a Window (ie call it up as <local:MyControl> ) I
    don't see values that I initialised in the code behind the control taking
    effect in the control

    I'm sure this might be a datacontext issue in my Window, but I don't see how
    to resolve it given that there are no actual bindings setup in the
    Window1.xaml itself.



    Thanks for any general suggestions or blog pointers.
    --
    Griff
    (trying to make an industrial UI with XAML/WPF/c#)

      My System SpecsSystem Spec

  2. #2


    Griff Guest

    RE: Data Binding in user control

    I have discovered what was going wrong.

    I was generating my control from the UserControl base class. I could not
    get any databinding to work.
    I changed to ContentControl.
    Now everything works.


    --
    Griff
    (trying to make an industrial UI with XAML/WPF/c#)


    "Griff" wrote:

    > I can do this
    > - create a Window
    > - define a Dependency property in the code behind the Window
    > - bind this property it to the content of some standard control placed in
    > the Window
    > (Eg a TextBlock which displays a string set in the code behind)
    > So far so good.
    >
    > But when I
    > - create a custom control (MyControl.xaml & MyControl.xaml.cs)
    > - define dependency properties in the code behind the control
    > - use those properties in the markup for the control to define its appearance
    > - deploy the control in a Window (ie call it up as <local:MyControl> ) I
    > don't see values that I initialised in the code behind the control taking
    > effect in the control
    >
    > I'm sure this might be a datacontext issue in my Window, but I don't see how
    > to resolve it given that there are no actual bindings setup in the
    > Window1.xaml itself.
    >
    > Thanks for any general suggestions or blog pointers.
    > --
    > Griff
    > (trying to make an industrial UI with XAML/WPF/c#)


      My System SpecsSystem Spec

  3. #3


    Jason Dolinger Guest

    Re: Data Binding in user control

    Griff wrote:
    > I have discovered what was going wrong.
    >
    > I was generating my control from the UserControl base class. I could not
    > get any databinding to work.
    > I changed to ContentControl.
    > Now everything works.
    >
    >


    ContentControl, eh...? I'll have to try that now! Can anyone MS
    people in this ng (Tina, anyone?) explain what the architectural
    differences are?

    Thanks,
    Jason

      My System SpecsSystem Spec

  4. #4


    Rob Relyea [MSFT] Guest

    Re: Data Binding in user control

    UserControl may actually become a subclass of content control in a future
    CTP...if that goes through successfully, there will be no difference to
    describe.

    :-)

    Thanks,
    Rob Relyea
    WPF Program Manager
    http://longhornblogs.com/rrelyea

    "Jason Dolinger" <jdolinger@lab49.com> wrote in message
    news:%230FoZezBGHA.984@tk2msftngp13.phx.gbl...
    > Griff wrote:
    >> I have discovered what was going wrong.
    >>
    >> I was generating my control from the UserControl base class. I could
    >> not get any databinding to work.
    >> I changed to ContentControl.
    >> Now everything works.

    >
    > ContentControl, eh...? I'll have to try that now! Can anyone MS people
    > in this ng (Tina, anyone?) explain what the architectural differences are?
    >
    > Thanks,
    > Jason




      My System SpecsSystem Spec

Data Binding in user control

Similar Threads
Thread Thread Starter Forum Replies Last Post
Binding to properties of a user control Dave Avalon 1 10 Apr 2008
User Account Control & Data in the Program Files Folder Brian T Vista account administration 1 24 Jul 2007
Data Binding of user control property luba Avalon 1 27 Oct 2006
Data binding in a FlowDocument Mark at S&W Avalon 0 13 May 2006
data binding Joerg Engel Avalon 1 22 Mar 2006