none
Binding to a UserControl Dependency Property

    Question

  • Hello,

    I've got a UserControl, containing a DevXpress Scheduler control in which  I try to bind a property to a dependency property of my USerControl, like this :

     

    <dxsch:ResourceStorage DataSource="{Binding Path=ReservationCourtCollection, 
    RelativeSource={RelativeSource FindAncestor, AncestorType=Gui:UCReservations}}
    ">

     


    Namespace Gui defined as my main application's namespace.

    But I got an error in the output window : "Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='TennisClub.UCReservations', AncestorLevel='1''."

    The weird thing is that I defined the binding using the property panel, selecting for Source FindAncestor=>UCReservations, which then displayed in Path pane my dependency property ReservationCollection... (so at design time, the property is well found)

    What am I doing wrong ?


    Friday, September 30, 2011 6:03 PM

Answers

  • Use just the Relative Source as UserControl as below

    <dxsch:ResourceStorage DataSource="{Binding Path=ReservationCourtCollection, 
    RelativeSource={RelativeSource AncestorType=UserControl}}
    ">
    Saturday, October 1, 2011 8:58 PM
  • Ok, so after testing and testing again, I just realized that the problem didn't come from the binding but from the way my collections were populated !

    So, the binding :

    DataSource = "{Binding ReservationCollection}"

    works fine.

    Thanks for help !

    Saturday, October 1, 2011 9:24 PM
  • Hi Rao,

    You well understood. The Dependency Property is part of the UserControl UCReservations. I've already tried

    DataSource = "{Binding MyDP}"

    but it seems not to work...

    • Marked as answer by jacquesprogram Saturday, October 1, 2011 9:24 PM
    Saturday, October 1, 2011 2:21 PM

All replies

  • It could be UCReservations lives upper than 1 level in the visual tree, the trace just says that it couldn't find the type upper 1 level.

    Is it working at runtime?

    Saturday, October 1, 2011 3:57 AM
  • Hi,

    first of all i need to cleat what i have understood from ur question..

    u have a user control like this

    <UserControl>
    <DevExpressControl DataSource={U want to bind here} />
    </UserControl>
    


    and the Dependency property is the part of the same usercontrol????? or a different usercontrol like UserContol2???

    if first is true than u can simply bind , no need to use the RelativeSource

    DataSource = {"Binding UR Dependency Property"}

    please correct me if i misunderstood ur issue..

     

     


    Thanks, BHavik
    Saturday, October 1, 2011 5:09 AM
  • Hello,

    if you try to bind to the control as BAO said(usercontrol->inside SheduleControl) you can use ElementName where the name is the name of the UserControl.

    Saturday, October 1, 2011 12:37 PM
  • Hi Rao,

    You well understood. The Dependency Property is part of the UserControl UCReservations. I've already tried

    DataSource = "{Binding MyDP}"

    but it seems not to work...

    • Marked as answer by jacquesprogram Saturday, October 1, 2011 9:24 PM
    Saturday, October 1, 2011 2:21 PM
  • Also using ElementName doesn't work...
    Saturday, October 1, 2011 2:22 PM
  • Can you please post more code so we might give further assistance.
    Saturday, October 1, 2011 2:26 PM
  • Use just the Relative Source as UserControl as below

    <dxsch:ResourceStorage DataSource="{Binding Path=ReservationCourtCollection, 
    RelativeSource={RelativeSource AncestorType=UserControl}}
    ">
    Saturday, October 1, 2011 8:58 PM
  • Ok, so after testing and testing again, I just realized that the problem didn't come from the binding but from the way my collections were populated !

    So, the binding :

    DataSource = "{Binding ReservationCollection}"

    works fine.

    Thanks for help !

    Saturday, October 1, 2011 9:24 PM
  • Hi jacquesprogram,

    Sorry for my jumping in, I will mark proper reply as the answer of this thread, it will be helpful for others having similar concern.

     

    best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, October 3, 2011 2:14 AM
    Moderator