Avalonia: TextBox Selected Border


Overview

The following is code that can be used to change the system default BorderThickness and BorderBrush on a TextBox in Avalonia 11. The important parts are the selectors for /template/ and focus /template.

My first failed attempt (and yours also probably if you are here) was to simply change those values on the TextBox control directly but that didn't change the border when the control was selected.

For reference, as of the posting of this blog entry I have tested this on Avalonia 11 only.

XAML

<Window.Styles>
	 <Style Selector="TextBox">
				<Setter Property="BorderThickness" Value=".9, .9, .9, .9" />
				<Setter Property="BorderBrush" Value="#ccc" />
		</Style>
		<Style Selector="TextBox /template/ Border#PART_BorderElement">
				<Setter Property="BorderThickness" Value=".9, .9, .9, .9" />
				<Setter Property="BorderBrush" Value="#ccc" />
		</Style>
		<Style Selector="TextBox:focus /template/ Border#PART_BorderElement">
				<Setter Property="BorderThickness" Value=".9, .9, .9, .9" />
				<Setter Property="BorderBrush" Value="#ccc" />
		</Style>
</Window.Styles>