Search code examples
c#avaloniauiavalonia

Change Button Foreground in :pointerover and :pressed states


In fluent theme i can't change button Foregrounds in this states. In Github i find this code:

<Style Selector="^:pointerover /template/ ContentPresenter#PART_ContentPresenter">
      ...
      <Setter Property="Foreground" Value="{DynamicResource ButtonForegroundPointerOver}" />
 </Style>

But my project can't build with Foreground on ContentPresenter#PART_ContentPresenter.


Solution

  • ContentPresenter does not have a Foreground property. If you target a TextBlock you could use attached property TextBlock.Foreground. If not, there are child and descendant selectors you may want to take look at.

    Also the nested selector ^ does not seem to be documented (it's pretty new it seems), maybe it would be safer to just use name of the control (Button in your case) for now.