WPF TextBox TextProperty 元数据覆盖
如何重写 TextProperty
Metadata 以设置 UpdateSourceTrigger.PropertyChanged
默认情况下,在使用基本 TextBox
类方法的功能时
TextBox.OnTextPropertyChanged
TextBox.CoerceText
,当提到的两者都是私有的时?
public class MyTextBox : System.Windows.Controls.TextBox
{
static MyTextBox()
{
TextProperty.OverrideMetadata(typeof(TextBox), new FrameworkPropertyMetadata(
string.Empty, FrameworkPropertyMetadataOptions.Journal | FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
new PropertyChangedCallback(TextBox.OnTextPropertyChanged),
new CoerceValueCallback(TextBox.CoerceText), true, UpdateSourceTrigger.PropertyChanged));
...
How to override the TextProperty
Metadata to set the UpdateSourceTrigger.PropertyChanged
by default while using the functionality from the base TextBox
Class
TextBox.OnTextPropertyChanged
TextBox.CoerceText
methods, when both mentioned are private ?
public class MyTextBox : System.Windows.Controls.TextBox
{
static MyTextBox()
{
TextProperty.OverrideMetadata(typeof(TextBox), new FrameworkPropertyMetadata(
string.Empty, FrameworkPropertyMetadataOptions.Journal | FrameworkPropertyMetadataOptions.BindsTwoWayByDefault,
new PropertyChangedCallback(TextBox.OnTextPropertyChanged),
new CoerceValueCallback(TextBox.CoerceText), true, UpdateSourceTrigger.PropertyChanged));
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该能够使用 GetDefaultMetadata 方法,该方法将使您能够访问引用私有方法的回调。
以下对我有用:
You should be able to use the GetDefaultMetadata method which will give you access to the callbacks that refer to the private methods.
The following worked for me: