如果可见,如何在没有垂直滚动条的情况下获取或计算 ListBox 的实际宽度 [英] How to get or compute actual width of ListBox without Vertical Scrollbar if visible

查看:15
本文介绍了如果可见,如何在没有垂直滚动条的情况下获取或计算 ListBox 的实际宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何获取或计算 ListBox 的实际宽度而没有 垂直滚动条(如果可见).

I wonder how to get or compute actual width of ListBox without Vertical Scrollbar if visible.

我想要做的是改变 ListBox 内每个项目的宽度,而不被 垂直滚动条覆盖.

What I want to do is changing width of each items inside ListBox without being covered by Vertical Scrollbar.

Width="{Binding ActualWidth, 
    RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBox}}}

至少,上面的绑定告诉我ListBox的实际宽度,但是这个不处理垂直滚动条的宽度.

At least, above binding tell me the actual width of ListBox, but this one does not handle width of vertical scrollbar.

有什么好的方法可以解决这个问题吗?

Is there any good way to solve this?

推荐答案

尝试绑定到包含 ScrollViewerViewportWidth 属性.

Try binding to the ViewportWidth property of the containing ScrollViewer instead.

像这样:

Width="{Binding Path=ViewportWidth, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ScrollViewer}}"

这篇关于如果可见,如何在没有垂直滚动条的情况下获取或计算 ListBox 的实际宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆