【发布时间】:2011-11-17 10:40:00
【问题描述】:
我在派生的 AutoCompleteBox 控件上创建了一个 DependencyProperty --> IsReadOnly
从那里,我尝试通过转换器设置值 (T/F)。根据转换器的值,我想在 DependencyProperty 的设置器中更新嵌套的 TextBox 样式。在 XAML (IsReadOnly="True") 中显式设置属性可以正常工作,并且 setter 会触发并更新样式。但是,通过转换器执行此操作不会触发 DependencyProperty 的设置器。我似乎无法在此处粘贴代码 sn-ps(第一次发帖).. 所以我会尽我所能提供一个快速的代码运行:
AutoCompleteBox 上的属性:
IsReadOnly="{Binding Converter={StaticResource IsReadOnlyVerifier}, ConverterParameter='Edit Client'}"
调用转换器,它根据用户的权限返回真或假。但是,这不会调用已注册的 DependencyProperty 的设置器。
.. 设置
{
if (value)
{
var style = StyleController.FindResource("ReadOnlyTextBox") as Style;
TextBoxStyle = style;
}
else
{
TextBoxStyle = null;
}
SetValue(IsReadOnlyProperty, value);
}
【问题讨论】:
标签: silverlight dependencies properties dependency-properties converter