简体   繁体   English

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

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

In listbox contains multiple listitem, it will show first 5 record in listbox based on listbox height. 在列表框中包含多个列表项,它将基于列表框高度显示列表框中的前5条记录。 If I scroll the listbox item 7th record or any in first position. 如果我滚动列表框项目的第7条记录或第一个位置。 if user scroll the listboxitem, I need to find out the listbox selected item which position is visible(with in 5 records displaying in listbox based on height) 如果用户滚动listboxitem,我需要找出位置可见的listbox选定项(基于高度在listbox中显示5条记录)

Edit: 编辑:

lstbxindex.ItemContainerGenerator.ContainerFromItem(lstbxindex.SelectedItem);

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

Using this code I got the relative position of listbox selecteditem. 使用此代码,我得到了列表框selecteditem的相对位置。 if user scroll the listbox item after scroll need to overlay the textbox to the particular selected item position in listbox. 如果用户在滚动后滚动列表框项目,则需要将文本框覆盖到列表框中特定的选定项目位置。 So I check the condition like, 所以我检查情况,

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

so I check 所以我检查

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

In winforms you could access the top visible item by using Listbox.TopIndex Property please check whether it is implemented in WPF !! 在winforms中,您可以使用Listbox.TopIndex属性访问顶部可见的项目,请检查它是否在WPF中实现! below is the sample code in WINFORM App. 下面是WINFORM App中的示例代码。

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

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

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