【发布时间】:2020-06-21 15:50:37
【问题描述】:
我学习 C# 已经有几天了,但我遇到了一个奇怪的问题。我在 WPF 应用程序中有一个 TextBox,它通常可以正常工作,但是在我在 XAML 中对其应用自定义模板后,它会停止返回文本值。它总是空字符串。
我在 XAML 中的模板:
<ControlTemplate x:Key="TextBoxBaseControlTemplate" TargetType="{x:Type TextBoxBase}">
<Border x:Name="Bd" BorderBrush="DarkGray" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="4,4,4,4">
<TextBox Background="#353535" Foreground="White"/>
</Border>
</ControlTemplate>
我在 XAML 中的文本框:
<TextBox x:Name="TextBox" Template="{StaticResource TextBoxBaseControlTemplate}" Foreground="White" BorderThickness="1" BorderBrush="DarkGray" HorizontalAlignment="Stretch" Height="23" Margin="53,0,105,15" TextWrapping="Wrap" Text="Enter city" VerticalAlignment="Bottom" GotFocus="TextBox_GotFocus" KeyDown="TextBox_KeyDown"/>
我该如何解决这个问题?
【问题讨论】: