【发布时间】:2011-05-29 09:40:52
【问题描述】:
我有一个 ValueConverter 需要使用动态参数调用,具体取决于属性。我看不到这样做的方法...
Width="{Binding ActualWidthValue, Source={StaticResource VisibleSize}, Converter={StaticResource Fraction}}"
“分数”转换器获取(或应该获取)System.Size 类型的参数,其中包含分子和分母。该值(应该)取决于 ItemCollection.Count。重置 ItemCollection 应该使用新值重新调用 Converter。
我的第一个想法是在我的 ItemCollection DependencyProperty 的 PropertyChanged 事件上手动更改 CodeBehind 中的 ConverterParameter。但是,正如我现在所知,Silverlight 没有 GetBinding() 方法。 我听说过 GetBindingExpression 并尝试去做。但是 MyGrid.GetBindingExpression(Grid.ActualHeightProperty) 总是返回 null,尽管 Binding 已经建立。
那么,我该怎么做才能达到我的目标?
我的实现并没有太大的不同。在通过 Binding 调用 Converter 之前,我在 CodeBehind 中设置了 ConverterParameter。这不起作用(参数仍然包含初始化值)。
我会尝试使用您的建议。但是为什么 ConverterParameter 不能是 DependencyPropery。这背后的想法是什么?有人知道吗?
【问题讨论】:
标签: silverlight dynamic binding converter