I was adding some workaround code to fix the bug outlined in Is this a bug in DotNet 4 WPF Spell Checking?, (When a WPF TextBox changes Enabled,
Visible
or ReadOnly
states, any SpellCheck custom dictionaries get dropped off until you disable and re-enable SpellCheck) and the simplest fix seemed to be to handle the IsVisibleChanged
, IsEnabledChanged
, and IsReadOnlyChanged
events.
我正在添加一些解决方法代码来修复在这是DotNet 4 WPF拼写检查中的错误中概述的错误?(当WPF TextBox更改Enabled,Visible或ReadOnly状态时,任何SpellCheck自定义词典都会被删除,直到您禁用并重新启动启用SpellCheck)和最简单的修复似乎是处理IsVisibleChanged,IsEnabledChanged和IsReadOnlyChanged事件。
Simple, right? Except there is no IsReadOnlyChanged
event. Anybody know why and what the best way to trap a change to IsReadOnly
in a WPF TextBox would be?
简单吧?除了没有IsReadOnlyChanged事件。任何人都知道为什么以及在WPF TextBox中捕获对IsReadOnly的更改的最佳方法是什么?
2 个解决方案
#1
7
You can always follow dependency property change with DependencyPropertyDescriptor.AddValueChanged
您始终可以使用DependencyPropertyDescriptor.AddValueChanged跟踪依赖项属性更改
DependencyPropertyDescriptor.FromProperty(TextBoxBase.IsReadOnlyProperty)
.AddValueChanged(ctrl, OnReadOnlyChanged)
#2
0
Create a custom class and handle OnPropertyChanged event. Sth like this:
创建自定义类并处理OnPropertyChanged事件。是这样的:
public class MyTextBox: TextBox
{
public MyTextBox() { }
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
{
base.OnPropertyChanged(e);
if (e.Property.ToString() == "IsReadOnly")
{
// here you are sure that ContentPropertyhas changed
}
}
}
#1
7
You can always follow dependency property change with DependencyPropertyDescriptor.AddValueChanged
您始终可以使用DependencyPropertyDescriptor.AddValueChanged跟踪依赖项属性更改
DependencyPropertyDescriptor.FromProperty(TextBoxBase.IsReadOnlyProperty)
.AddValueChanged(ctrl, OnReadOnlyChanged)
#2
0
Create a custom class and handle OnPropertyChanged event. Sth like this:
创建自定义类并处理OnPropertyChanged事件。是这样的:
public class MyTextBox: TextBox
{
public MyTextBox() { }
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
{
base.OnPropertyChanged(e);
if (e.Property.ToString() == "IsReadOnly")
{
// here you are sure that ContentPropertyhas changed
}
}
}