“{BindingrelativeSource={RelativeSourceFindAncestor”的问题

发布于 2024-08-17 21:38:53 字数 396 浏览 1 评论 0原文

我正在开发一个 Prism Composite 应用程序,将不同的视图加载到一个区域中。我需要确保我正在加载的视图的大小调整为与该区域相同的高度。每个视图都是一个用户控件,其外部元素为 Grid。我正在使用以下代码

    <Grid  Height="{Binding RelativeSource={RelativeSource FindAncestor,
        AncestorType={x:Type ItemsControl}}, Path=ActualHeight}">

来设置网格的高度。我的问题是,这个确切的代码适用于一个视图,但不适用于另一视图。在不起作用的网格上,高度是我所期望的,就好像未设置 Height 属性一样。

有关如何解决此问题的任何建议。

I'm working on a Prism Composite application where I load different views into a region. I need to make sure that the view I'm loading is resized to the same height as the region. Each view is a usercontrol that has a Grid as the outer element. I'm using the following code

    <Grid  Height="{Binding RelativeSource={RelativeSource FindAncestor,
        AncestorType={x:Type ItemsControl}}, Path=ActualHeight}">

To set the height of the grid. My problem is that this exact code works fine for one view and doesn't for another view. On the grid that doesn't work, the height is what I would expect as if the Height property is not being set.

Any suggestions on how to trouble shoot this.

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

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

发布评论

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

评论(1

ぃ双果 2024-08-24 21:38:53

在了解不多的情况下,我想说这个问题实际上归结为一个具有约束力的问题。调试绑定很棘手,但是这里有一篇关于该主题的非常好的文章:
http://www.beacosta.com/blog/?p=52

使用Bea 描述的“diagnostics:PresentationTraceSources.TraceLevel=High”方法,并通过观察输出窗口找出您实际绑定到的元素。这应该有助于找出它失败的原因。

祝你好运。

Without knowing much, I'd say this issue really just boils down to a binding issue. Debugging bindings is tricky, but there is a really great article on the subject here:
http://www.beacosta.com/blog/?p=52

Use the "diagnostics:PresentationTraceSources.TraceLevel=High" approach that Bea describes and find out what element you are actually binding to by watching the output window. That ought to help figure out why it's failing.

Good luck.

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