locked
Template Binding of Attached properties RRS feed

  • Question

  • Hi,

     

    I have Attached Property and ControlTemplate using the attached property.

    This is simplified the control template:

    < ControlTemplate >…

    < Border >

    <ToggleButton  IsChecked="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=assm:Helper.IsSomething, Mode=TwoWay }">
    </Border>
    </ControlTemplate>
     

     And below is how it is used in the application.

     <ListBox  asm:Helper.IsSomething="{Binding IsSomething, Mode=TwoWay}"/>

    The problem is, when I toggle the toggleButton, it IsChecked state does not get updated the asm.Helper.IsSomething property.

    I tried multiple ways to bindthe IsChecked from the ToggleButton in the control to the attached property set in the application, but no success. Any suggestions?

    Thanks a lot

    Wednesday, February 1, 2012 10:36 AM

Answers

  • Seems that the answer was not that difficult, so here it is. Believe it or not, what I missed in the many trails is that it ha to be named specifically Path= when binding to an attached property, and the attached property needs to be in braces ().

     

     IsChecked="{Binding Path=(asm:Helper.IsSomething), Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}">
    

    • Marked as answer by viktorg1 Wednesday, February 1, 2012 11:43 AM
    Wednesday, February 1, 2012 11:39 AM

All replies

  • Seems that the answer was not that difficult, so here it is. Believe it or not, what I missed in the many trails is that it ha to be named specifically Path= when binding to an attached property, and the attached property needs to be in braces ().

     

     IsChecked="{Binding Path=(asm:Helper.IsSomething), Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}">
    

    • Marked as answer by viktorg1 Wednesday, February 1, 2012 11:43 AM
    Wednesday, February 1, 2012 11:39 AM
  • Hi viktorg1,

    Glad to hear that you have resolved your issue, and thanks for sharing your solution here.

     

    Best regards,


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

    Thursday, February 2, 2012 6:49 AM