这是我的自定义控件,具有自定义 xaml 样式:
using System.Windows.Controls;
namespace MyControls
{
public class CustomTextBox : TextBox
{
}
}
<Style TargetType="controls:CustomTextBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:CustomTextBox">
<StackPanel>
<TextBlock Text="" />
<TextBox Text="{TemplateBinding Text}" />
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
并且在使用时,处理程序由于某种原因TextChanged
没有得到更新的字段。Text
<controls:CustomTextBox x:Name="ControlInstance"
TextChanged="OnTextChanged"
InputScope="EmailNameOrAddress" />
private void OnTextChanged(object sender, TextChangedEventArgs e)
{
// ControlInstance.Text is always ""!
}