派生自 Binding 类 (Silverlight 4.0)
使用现有的 Binding
类,我们可以编写,
<TextBox Text="{Binding Email, Mode=TwoWay}"/>
因此我们可以将任何内容写为电子邮件; Binding
本身不进行有效性检查。我开始编写一个从 Binding
派生的类 BindingMore
,以便最终我可以编写,
<TextBox Text="{local:BindingMore Email, Validate=SomeMethod, Mode=TwoWay}"/>
其中 SomeMethod
是一些 ICommand
或delegate
将被触发以验证 Email
。这是我的目标,但我还没有写下来。
截至目前,我只编写了这段代码,
public class BindingMore : System.Windows.Data.Binding
{
public BindingMore() : base()
{
}
public BindingMore(string path) : base(path)
{
}
}
因此,在这个阶段, BindingMore
与 Binding
完全相同,但是当我编写时,
<TextBox Text="{local:BindingMore Email, Mode=TwoWay}"/>
它给了我运行时错误。但当我写的时候,
<TextBox Text="{local:BindingMore Path=Email, Mode=TwoWay}"/>
它工作得很好。谁能告诉我为什么在第一种情况下会出现运行时错误?
不幸的是,错误没有显示出来。它所显示的只是这样:
另外,我从 XAML 收到以下错误消息(即使它完美构建并运行(在第二种情况下)) ):
类型“local:BindingMore”的用法如下 标记扩展但不派生 来自标记扩展。
Using the existing Binding
class, we can write,
<TextBox Text="{Binding Email, Mode=TwoWay}"/>
So we can write anything as Email; there is no validity check by Binding
itself. I started writing a class BindingMore
deriving from Binding
so that eventually I could write,
<TextBox Text="{local:BindingMore Email, Validate=SomeMethod, Mode=TwoWay}"/>
Where SomeMethod
is some ICommand
or delegate
which will be triggered to validate the Email
. That is my objective, and I've not written that yet.
As of now, I've written just this code,
public class BindingMore : System.Windows.Data.Binding
{
public BindingMore() : base()
{
}
public BindingMore(string path) : base(path)
{
}
}
So, at this stage, BindingMore
is exactly equivalent to Binding
, yet when I write
<TextBox Text="{local:BindingMore Email, Mode=TwoWay}"/>
It's giving me runtime error. But when I write,
<TextBox Text="{local:BindingMore Path=Email, Mode=TwoWay}"/>
It's working fine. Can anybody tell me why it's giving runtime error in the first case?
Unfortunately, the error is not shown. All it shows is this:
Also, I get the following error message from XAML (even when it builds perfectly and runs (in the second case)):
Type 'local:BindingMore' is used like
a markup extension but does not derive
from MarkupExtension.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Silverlight
不支持自定义标记扩展
。尝试使用附加属性
方法或行为
。Custom
Markup Extensions
are not supported inSilverlight
. Try using anAttached Property
approach or aBehavior
.