Template Binding with Attached Properties

前端 未结 2 523
囚心锁ツ
囚心锁ツ 2020-12-01 17:46

I have a standard style for my buttons but I want certain parts of the style to be configurable. e.g. I have a border appear when MouseOver is triggered for the button and I

相关标签:
2条回答
  • 2020-12-01 18:46

    I think TemplateBinding is evaluated at compile time so you can't dynamically set a TemplateBinding in your Setter, try using Binding instead (see below).

    <Setter TargetName="border" Property="BorderBrush" 
            Value="{Binding Path=(local:ThemeProperties.ButtonBorderColour),
                            RelativeSource={RelativeSource TemplatedParent}}"/>
    

    Hope this helps.

    0 讨论(0)
  • 2020-12-01 18:50

    Try this:

    <Setter TargetName="border" Property="BorderBrush" Value="{TemplateBinding Path=(local:ThemeProperties.ButtonBorderColour)}" />
    

    The difference being that parentheses around the property indicate that it is an attached property.

    0 讨论(0)
提交回复
热议问题