问题描述
你好,
在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,
推荐答案
如果要使用外部ScrollViewer
滚动整个ListBox
的内容,请省略包装的ListBox
的Height
属性.
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中滚动滚动查看器后,无法在列表框中选择项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!