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

问题描述 投票:0回答:1

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>

等等

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。

按钮边框厚度不会更改为5,这是不正常的。

这个问题看起来像未解决的问题:

Button border thickness from code behind

c# wpf vb.net xaml
1个回答
0
投票

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

The answer to this question is very useful

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

© www.soinside.com 2019 - 2024. All rights reserved.