简体   繁体   中英

Button border thickness doesnt change from code behind

XAML

<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">

<Grid>
    <Button x:Name="Button1" Background="LightGreen" Height="50" Width="70"/>
</Grid>
</Window>

vb

Class MainWindow 
Private Sub MainWindow_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
    Button1.BorderBrush = Brushes.Red
    Button1.BorderThickness = New Thickness(5)
End Sub
End Class

When you run the codes above you will see that;

Button1 border brush changes to red which is okey.

Button1 border thickness doesnt change to 5 which is not okey.

This issue is look like unsolved:

Button border thickness from code behind

Like Erno de Weerd said in the comments it could be a template issue. I've been burned by this several times starting out.

The answer to this question is very useful

It talks about using the {TemplateBinding} expression when binding in a controls template

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM