在WPF中滚动滚动查看器后,无法在列表框中选择项目 [英] Unable to select the items in a Listbox after scrolling the scroll viewer in WPF

查看:82
本文介绍了在WPF中滚动滚动查看器后,无法在列表框中选择项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
在WPF中滚动scrollviewer后,iam无法在列表框中选择项目.
此后,当我滚动到下一个项目时,只能选择列表框所显示的项目.这些项目无法选择.

样本:
XAML

Hello,
iam unable to select the items in a Listbox after scrolling the scrollviewer in WPF.
only able to select the items up to which the listbox is displaying after that when i scroll for the next items, those are unable to select.

sample:
XAML

<ScrollViewer
 x:Name="dataScroller"
 VerticalScrollBarVisibility="Disabled"
 HorizontalScrollBarVisibility="Auto">
    <ListBox
	Name="mylistbox"
	Grid.Row="1"
	HorizontalAlignment="Stretch"
	VerticalAlignment="Bottom"
	Height="50"
	SelectionChanged="Mylistbox_SelectionChanged" />
</ScrollViewer>

<Label
Name="label1"
Content="Label"
Grid.Column="0"
Grid.Row="0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="28,13,0,0"
Width="92"
Height="23" />



C#代码:

构造函数



C# code:

Constructor

public Window1()
   {
      InitializeComponent();
      this.WindowState= WindowState.Maximized;
      List<string> mylist=new List<string> ();
      for(int i=0;i<=50;i++)
      {
        mylist.Add(" item" + i);
      }
            mylistbox.ItemsSource=mylist;
   }
void Mylistbox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
  label1.Content=mylistbox.SelectedItem.ToString();
}



请帮助滚动到列表框中的下一个项目后,如何在列表框中选择项目

谢谢,



Plz help how i can select the items in a listbox after scrolling to the next items in the list box

Thanks,

推荐答案

hi
对于ListBox,必须使SelectionMode ="Multiple"(这是一个ListBox属性).那么它将为您工作.



问候
Siraz
hi
For ListBox you have to make SelectionMode="Multiple"(This is a ListBox Property) . then it will be Work for you.



Regards
Siraz


为什么使用ListBoxHeight属性?

如果要使用外部ScrollViewer滚动整个ListBox的内容,请省略包装的ListBoxHeight属性.

If you want to scroll the whole of the ListBox''s content with the outer ScrollViewer, omit the Height property of the wrapped ListBox.


这篇关于在WPF中滚动滚动查看器后,无法在列表框中选择项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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