针对 Blend 中的 CLR 对象的 Silverlight 数据绑定

发布于 2024-07-18 16:34:23 字数 517 浏览 8 评论 0原文

我喜欢 Blend 中的功能,您可以在其中设置与 CLR 对象的数据绑定,并设计您的 Silverlight 控件/页面。 我的问题是关于创建将用作数据模板的用户控件。 这一切在 Blend 中都很有效,但仅限于设计时。 问题是,当我在 Blend 中编辑控件,并将文本框绑定到 CLR 对象的属性时,它会给出以下信息:

Text="{Binding Mode=OneWay, Path=TestAccount.Name, Source={StaticResource TestDataDS}}"

但是当我准备好运行应用程序并在 DataTemplate 中使用该用户控件时比如说一个列表框,我需要它看起来像这样:

Text="{Binding Mode=OneWay, Path=Name}"

如何使用漂亮的绑定在 Belnd 中进行设计,但在准备运行项目时不必触摸/搜索并替换所有这些绑定? 我正在寻找一种在设计时和运行时都有效的方法。

谢谢,

I love the feature in Blend where you can setup databinding to CLR Objects, and design your Silverlight control/page. My issue is around the creation of a user control that will be used as a DataTemplate. It all works great in Blend, but only at design time. The issue is that when I am editing the control in Blend, and I bind say a textbox to the property of a CLR object, it gives me this:

Text="{Binding Mode=OneWay, Path=TestAccount.Name, Source={StaticResource TestDataDS}}"

But when I am ready to run the app, and use that user control inside a DataTemplate for say a list box, I need it to just look like this:

Text="{Binding Mode=OneWay, Path=Name}"

How can I use the nifty binding to design in Belnd, but not have to touch/search&replace all these bindings when I am ready to run the project? I am looking for an approach that will work both in design time and at run time.

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

彩虹直至黑白 2024-07-25 16:34:23

为了在 Expression Blend 中创建到 CLR 对象的数据绑定,您不需要使用“创建数据绑定”对话框的“数据字段”选项卡。 事实上,这样做的情况非常罕见。

使用自定义路径表达式是最常见的方法。 只需选中“使用自定义路径表达式”复选框,然后输入要绑定的属性的名称即可。 如果未指定数据上下文,则数据绑定将解析为您在恰好是 DataContext 的任何对象上指定的路径。

如果要设置设计时 DataContext,可以通过设置 d:DataContext 属性来实现,并确保正确定义 xmlns:d="..."

In order to create a data binding to a CLR object in Expression Blend, you don't need to use the "DataField" tab of the "Create Data Binding" dialog. In fact, doing it this way is very rare.

Using a custom path expression is the most common way. Simply checking the "Use a custom path expression" check box and then typing in the name of the property that you would like to bind to. If you leave the data context unspecified, then the data binding will resolve to the path that you specified on whatever object happens to be the DataContext.

If you want to set a design time DataContext you can do that by setting the d:DataContext property, making sure to properly define xmlns:d="..."

放手` 2024-07-25 16:34:23

如果您使用的是 Blend 2,我建议您查看 Jonas Follesoe 的设计时/运行时使用依赖注入的博客文章

如果您有幸使用 Blend 3,则检查一下

当您在 Blend 中设置绑定时,“显式数据上下文”选项卡可用吗?

If you're using blend 2, I'd recommend you take a look at Jonas Follesoe's design time / run time blog post which uses dependency injection.

If you're lucky enough to be using Blend 3, then check this out

When you're setting bindings up in blend, is the "Explicit Data Context" tab available?

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