按钮边框厚度不会从代码后面改变

时间:2018-03-01 20:23:47

标签: c# wpf vb.net xaml

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

当你运行上面的代码时,你会看到;

Button1边框画笔变为红色,这是okey。

Button1的边框厚度不会变为5而不是okey。

此问题看似未解决:

Button border thickness from code behind

1 个答案:

答案 0 :(得分:0)

就像Erno de Weerd在评论中所说,它可能是一个模板问题。我已经被这几次烧伤了。

The answer to this question is very useful

它讨论了在控件模板中绑定时使用{TemplateBinding}表达式