绑定到复合路径

发布于 2024-11-07 17:47:53 字数 722 浏览 0 评论 0原文

我正在窗口 xaml 中创建资源。 该资源是一个控制器,就像这样,

<Window.Resources>
  <ext:Controller x:Key="Controller"/>
</Window.Resource>

我的 xaml 中有控件,我想将其绑定到控制器中的“复合成员”,可以这么说。 就像我在控制器中有一个字符串,我想绑定到该字符串长度

<TextBlock Text="{Binding Source={StaticResource Controller},Path=myString.Length}"/>

或类似的东西。

这似乎是一种奇怪的方法,但我想将所有这些成员保留在控制器中,而不是使它们成为单独的资源,以便它们可以访问控制器中的某些内容。

问题的真正本质是我有几个 Windows,我希望它们共享公共资源(控制器的实例)。 所以我在控制器中放置了控制器的静态实例。我实际上想要绑定,例如

<TextBlock Text="{Binding Source={StaticResource Controller},Path=StaticInstance.memberProperty/>

是否可以绑定到成员的成员,或者我应该使用什么方法而不是想要“绑定中的复合路径”?

谢谢你们! 感谢您的帮助

I'm creating a resource in the window xaml.
That resource is a controller, like this

<Window.Resources>
  <ext:Controller x:Key="Controller"/>
</Window.Resource>

I have controls in my xaml that I want to bind to "compund members" in the Controller, so to speak.
Like if I hade a string in the controller and I want to bind to that strings length

<TextBlock Text="{Binding Source={StaticResource Controller},Path=myString.Length}"/>

or something like that.

It seems like a weird way to do it but I want to keep all of those members in the controller as opposed to making them separate resources, so they have access to certain things in the controller.

The real essence of the problem is that I have a couple of Windows and I want them to share the common resource (an instance of Controller).
So i put a static instnace of controller in controller. i actually want to bind like

<TextBlock Text="{Binding Source={StaticResource Controller},Path=StaticInstance.memberProperty/>

Is it possible to bind to a member of a member or what approach should I be using instead of wanting the "compound path in the binding", so to speak?

Thanks, guys!
Appreciate the help

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

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

发布评论

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

评论(1

自由范儿 2024-11-14 17:47:53

StaticInstance 不是您的资源(它是一个实例)的属性,因为它是静态的。如果要绑定到静态成员,可以使用 x:Static< /code> 标记扩展,请注意语法非常具体。

绑定可能如下所示:

{Binding Source={x:Static myns:Controller.StaticInstance}, Path=memberProperty}

StaticInstance is not a property of your resource (which is an instance) since it is static. If you want to bind to static members you can use the x:Static markup extension, note that the syntax is quite specific.

The binding probably would look like this:

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