C
C#10mo ago
Kagano

✅ Avalonia UI button doesn't color by hover!

alls works great, but i doesnt change the color by Button:pointerover i have no plan why,
<UserControl.Styles>
<Style Selector="Button:pointerover">

<Setter Property="Width" Value="300"></Setter>
<Setter Property="Background" Value="Red"></Setter>
</Style>
<Style Selector="Button">

<Setter Property="Background" Value="Green"></Setter>
</Style>


<Button Content="Test"></Button>
</UserControl.Styles>
<UserControl.Styles>
<Style Selector="Button:pointerover">

<Setter Property="Width" Value="300"></Setter>
<Setter Property="Background" Value="Red"></Setter>
</Style>
<Style Selector="Button">

<Setter Property="Background" Value="Green"></Setter>
</Style>


<Button Content="Test"></Button>
</UserControl.Styles>
3 Replies
Honza K.
Honza K.10mo ago
you must change it in the template itself...
<Style Selector="Button:pointerover /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Background" Value="{DynamicResource Button.MouseOver.Background}"/>
<Setter Property="TextBlock.Foreground" Value="{DynamicResource Button.Foreground}"/>
</Style>
<Style Selector="Button:pointerover /template/ ContentPresenter#PART_ContentPresenter">
<Setter Property="Background" Value="{DynamicResource Button.MouseOver.Background}"/>
<Setter Property="TextBlock.Foreground" Value="{DynamicResource Button.Foreground}"/>
</Style>
Honza K.
Honza K.10mo ago
How To Troubleshoot Styles | Avalonia Docs
Much of the Avalonia UI styling system corresponds to CSS styling approaches. So without knowledge of this technology, you may find the hints here helpful.
Kagano
KaganoOP10mo ago
thank you very much
Want results from more Discord servers?
Add your server