Roberto Vargas
Roberto Vargas

Reputation: 89

Set max value for property Borderthickness

I have this component <Border Background="{TemplateBinding Background}" CornerRadius="3" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" x:Name="border"/> but I like to set the property BorderThickess with a max value, for example 5, in order of if I set BorderThickess = 25, automatically is setting in 5, the max value.

Upvotes: 0

Views: 96

Answers (1)

Melkor V
Melkor V

Reputation: 66

You can implement your logic through Binding (for example you have BorderThickness property in your ViewModel and on 'set' you can accomplish that check for max 5). Other way you can do it is through converter https://learn.microsoft.com/ru-ru/dotnet/desktop/wpf/data/how-to-convert-bound-data?view=netframeworkdesktop-4.8 by throwing the BorderThickness property itself and checking either its greater than 5 or not and return appropriate value. But converter is probably not the best way to do this so I suggest you to use DataBinding for your property and change logic in 'set' method of that property.

Upvotes: 1

Related Questions