################## JQuery (используйте API) ################# $ $ (document) .ready (function () {function getdate () {var today = new Date (); var h = today.getHours (); var m = today.getMinutes (); var s = today.getSeconds (); if (s & lt 10) {s = "0" + s;} $ ("h1"). Text (h + ":" + m + ":" + s); setTimeout (function () {getdate ()}, 500);} $ («кнопка»). click (getdate);}); ################## HTML ###################### & lt; button & gt; start clock & lt; / button & gt; & Lt; h1 & GT; & Lt; / h1 & GT;
Попробуйте установить
ScrollViewer.CanContentScroll="False"
в ListBox, он должен исправить проблему ctrl + a.
Если вы хотите получить все выбранные элементы, вы можете использовать свойство SelectedItems из ListBox. Вам не нужно добавлять свойство IsSelected к вашему объекту.
Проверьте пример.
Файл XAML:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal">
<Button Content="Selected items" Click="Button_Click" />
<Button Content="Num of IsSelected" Click="Button_Click_1" />
</StackPanel>
<ListBox Name="lbData" SelectionMode="Extended" Grid.Row="1">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="IsSelected" Value="{Binding Path=IsSelected, Mode=TwoWay}"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
</Grid>
Файл с кодом:
using System.Collections.Generic;
using System.Windows;
using System.Windows.Documents;
namespace ListBoxItems
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
List<MyBoundObject> _source = new List<MyBoundObject>();
for (int i = 0; i < 100000; i++)
{
_source.Add(new MyBoundObject { Label = "label " + i });
}
lbData.ItemsSource = _source;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show(lbData.SelectedItems.Count.ToString());
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
int num = 0;
foreach (MyBoundObject item in lbData.Items)
{
if (item.IsSelected) num++;
}
MessageBox.Show(num.ToString());
}
}
public class MyBoundObject
{
public string Label { get; set; }
public bool IsSelected { get; set; }
}
}