繁体   English   中英

如何使用相对位置设置textBox位置?

[英]How to set the textBox position Using Relative position?

在列表框中包含多个列表项,它将基于列表框高度显示列表框中的前5条记录。 如果我滚动列表框项目的第7条记录或第一个位置。 如果用户滚动listboxitem,我需要找出位置可见的listbox选定项(基于高度在listbox中显示5条记录)

编辑:

lstbxindex.ItemContainerGenerator.ContainerFromItem(lstbxindex.SelectedItem);

            System.Windows.Point relativePoint = lstbxindex.TransformToVisual(listBoxItem)
                               .Transform(new System.Windows.Point(0, 0));

使用此代码,我得到了列表框selecteditem的相对位置。 如果用户在滚动后滚动列表框项目,则需要将文本框覆盖到列表框中特定的选定项目位置。 所以我检查情况,

Listbox firstItem x=-2,y-2
Listbox secondItem x=-2,y=-56
Listbox thirdItem x=-2,y=-110
etc
relative position y increasing 54.

所以我检查

if(relativePoint.Y==56)
{
**//how to set the textbox to that relative position in listbox**
}

在winforms中,您可以使用Listbox.TopIndex属性访问顶部可见的项目,请检查它是否在WPF中实现! 下面是WINFORM App中的示例代码。

lstbxindex.Items[lstbxindex.TopIndex].ToString()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM