我正在开发一个Custom MarkupExtension,我需要一个来自XAML的非字符串参数来构造新对象.是否可以在datacontext范围内的字段上使用非字符串参数绑定?
换句话说,我该怎么办呢?
<ListBox ItemsSource="{Binding Source={local:MyMarkupExtension {x:Type Button},IncludeMethods={Binding Source=CustomerObject.IsProblematic}}}" />
Run Code Online (Sandbox Code Playgroud)
其中IncludeMethods=CustomerObject.IsProblematic
给我这个错误:绑定无法在类型"TypeDescriptorExtension"的"IncludeMethods"属性设置.'绑定'只能在DependencyObject的DependencyProperty上设置.
谁能帮我?
谢谢
EvA*_*lex 12
'绑定'只能在DependencyObject的DependencyProperty上设置 - 它是真的.问题是MarkupExtension
类不是派生的DependencyObject
,这就是为什么不能对它的属性设置绑定的原因.
[编辑]
解决方法是使用ValueConverters.另一种解决方法是更改C#语言以允许多重继承.顺便说一句,在Silverlight MarkupExtension
实现IMarkupExtension
接口,所以我尝试在我的自定义扩展中实现它并从中派生DependecyObject
,添加DependencyProperty
并设置绑定.它不会崩溃,但绑定实际上是在调用ProvideValue()之后设置的.因此,即使在Silverlight中也没有解决方案(或者很难 - 请参阅Klaus78答案中提供的链接).在WPF中,MarkupExtension不实现任何接口,因此您无法绑定到它的属性.
归档时间: |
|
查看次数: |
12126 次 |
最近记录: |