开发者

How can I bind to a ListBox's viewport width (i.e., width without scrollbar)?

I want to bind to my ListBox's viewport width. That is, the width of the content area, not counting the borders or the scrollbar:

  • When the vertical scroll bar is visible, I want the width of the area between the left border and the scrollbar;
  • when the vertical scroll bar is not visible, I want the width of the area between the left and right borders.

Alternatively, I could make do with with something that tells me whether or not the vertical scrollbar is currently visible.

This is for a control that will be outside the listbox -- I want to positi开发者_如何学JAVAon it above the listbox's viewport, and make sure it's always the same width as the viewport. I.e., I want to bind its width to the ListBox's viewport width.


What you want to do is very specific to the internals of the ListBox control template. In the code-behind you can easily find the ScrollViewer and you can then use these useful properties:

  • ScrollViewer.ComputedVerticalScrollBarVisibility
  • ScrollViewer.ViewportWidth

to control the width of your target control. But this tight coupling is characterstic of a composite control and if instead you override the ListBox control template and include your target control at the beginning you will find that you have complete access to the ScrollViewer and its useful properties from XAML and you can associate the widths with a binding without all the problems that trying to maintain independent controls cause.


You can use "binding Path=Width,ElementName=abc".

if you just want to dock a control on the top of another, you can use Grid as well

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜