2017-07-04 197 views
0

在列表框中包含多个listitem,它将根据列表框高度显示列表框中的前5条记录。如果我滚动列表框项目第7条记录或任何在第一个位置。如果用户滚动ListBoxItem中,我需要找出列表框中选择的项目,其位置是可见的(与基于高度5个记录在列表框中显示)如何设置文本框的位置使用相对位置?

编辑:

lstbxindex.ItemContainerGenerator.ContainerFromItem(lstbxindex.SelectedItem); 

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

使用此代码我得到了listbox 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** 
} 
+0

你的意思是向下滚动键盘或鼠标? –

+0

@sushil Mate通过鼠标向下滚动。 – user688

+0

所以你现在想要在该位置上设置文本框,就可以获得选择项的相对位置了? –

回答

0

在的WinForms,你可以通过使用Listbox.TopIndex物业请检查它是否在WPF中实现访问顶部可见的项目!以下是WINFORM App中的示例代码。

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