如何访问ListBox.ViewPort宽度信息 [英] How to access ListBox.ViewPort width information

查看:72
本文介绍了如何访问ListBox.ViewPort宽度信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,

我需要将控件的宽度绑定到列表框的宽度,不包括scrool bar的宽度,是否可见。

I need to bind the width of a control to the width of a Listbox excluding teh width of scrool bar wether there are visible or not.

为此,我尝试访问ScrollViewer视口宽度,但无法成功。

For that I try to access to the ScrollViewer Viewport width but could not succeed.

任何想法并访问它,将其绑定到mw控件通过XAML的宽度?

Any idea and to access it a,d bind it to mw control Width through XAML ?

感谢您的帮助

问候

推荐答案

你好wakefun,

Hi wakefun,

>>任何想法并且访问它a,通过XAML将它绑定到mw控制宽度?

>>Any idea and to access it a,d bind it to mw control Width through XAML ?

我们可以通过以下代码获取Listbox的ScrollViewer视口宽度,然后将其分配给VM的属性。

We could get Listbox's ScrollViewer Viewport width via the following code, then assign it to VM's property.

Decorator border = VisualTreeHelper.GetChild(ListBox1, 0) as Decorator;
if (border != null)
{
     ScrollViewer scrollViewer = border.Child as ScrollViewer;
     if (scrollViewer != null)
     {
          double viewportWidth = scrollViewer.ViewportWidth;          
     }
}

祝你好运,

张龙


这篇关于如何访问ListBox.ViewPort宽度信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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