我遇到了一些非常奇怪的事情,一个简单的WPF应用程序。
使用代码后端
<Window x:Class="ListBoxSelection.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ListBox ItemsSource="{Binding Path=Strings}" SelectionMode="Single"/>
</Grid>
</Window>
使用代码后端
public class ViewModel
{
public List<string> Strings { get; set; }
public ViewModel ()
{
Strings = new List<string> ();
Strings.Add ("A");
// add many items ...
Strings.Add ("A");
}
}
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow ()
{
InitializeComponent ();
DataContext = new ViewModel ();
}
}
当我点击一个单个项目时,如果我继续点击其他项目,则它们会聚合。点击已选择的项目不会有任何反应。让我感到困惑的是,我以前将数据绑定列表到ListBox,从未见过这种情况。我的操作系统是Win7(64位),使用VS2010,这种行为出现在.Net 3.5,.Net 3.5客户端框架,.Net 4和.Net 4客户端框架中。
额,我应该提到我预期会有常规、默认的单选行为。