派生自 Binding 类 (Silverlight 4.0)

发布于 2024-10-12 16:45:45 字数 1282 浏览 3 评论 0原文

使用现有的 Binding 类,我们可以编写,

 <TextBox Text="{Binding Email, Mode=TwoWay}"/>

因此我们可以将任何内容写为电子邮件; Binding 本身不进行有效性检查。我开始编写一个从 Binding 派生的类 BindingMore ,以便最终我可以编写,

 <TextBox Text="{local:BindingMore Email, Validate=SomeMethod, Mode=TwoWay}"/>

其中 SomeMethod 是一些 ICommanddelegate 将被触发以验证 Email 。这是我的目标,但我还没有写下来。

截至目前,我只编写了这段代码,

public class BindingMore : System.Windows.Data.Binding
{
    public BindingMore() : base() 
    { 
    }
    public BindingMore(string path) : base(path)
    {
    }
}

因此,在这个阶段, BindingMoreBinding 完全相同,但是当我编写时,

 <TextBox Text="{local:BindingMore Email, Mode=TwoWay}"/>

它给了我运行时错误。但当我写的时候,

 <TextBox Text="{local:BindingMore Path=Email, Mode=TwoWay}"/>

它工作得很好。谁能告诉我为什么在第一种情况下会出现运行时错误?

不幸的是,错误没有显示出来。它所显示的只是这样: alt text

另外,我从 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:
alt text

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

卷耳 2024-10-19 16:45:45

Silverlight 不支持自定义标记扩展。尝试使用附加属性方法或行为

Custom Markup Extensions are not supported in Silverlight. Try using an Attached Property approach or a Behavior.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文