我有一个 DataGrid,我只想在其中显示数据。我不想选择任何东西。但是,它总是希望选择第一行的第一列。
这是 XAML:
<myDataGrid:DataGrid
x:Name="grdPerson"
AutoGenerateColumns="False"
Height="478"
Width="302"
IsReadOnly="True"
RowBackground="Black"
AlternatingRowBackground="Gray"
GridLinesVisibility="None"
HeadersVisibility="Column"
Foreground="White"
CanUserReorderColumns="False"
CanUserResizeColumns="False"
CanUserSortColumns="False"
IsEnabled="False"
AreRowDetailsFrozen="True"
AreRowGroupHeadersFrozen="True">
<myDataGrid:DataGrid.Columns>
<myDataGrid:DataGridTextColumn
IsReadOnly="True"
Header="Date/Time"
Width="125"
Binding="{Binding Date}" />
<myDataGrid:DataGridTemplateColumn
IsReadOnly="True"
Header="Person"
Width="175">
<myDataGrid:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding FirstName}" />
<TextBlock Text="{Binding LastName}" />
</StackPanel>
</DataTemplate>
</myDataGrid:DataGridTemplateColumn.CellTemplate>
</myDataGrid:DataGridTemplateColumn>
</myDataGrid:DataGrid.Columns>
</myDataGrid:DataGrid>
这是填充网格的代码
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime Date { get; set; }
public Person(DateTime date, string firstName, string lastName)
{
Date = date;
FirstName = firstName;
LastName = lastName;
}
}
// in the MainPage.xaml
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
List<Person> list = new List<Person>();
list.Add(new Person(date: DateTime.Parse("4/14/2010 3:18 PM"), firstName: "John", lastName: "Doe"));
list.Add(new Person(date: DateTime.Parse("4/14/2010 5:18 am"), firstName: "Jane", lastName: "Doe"));
grdPerson.ItemsSource = list;
grdPerson.SelectedIndex = -1;
}
当显示 DataGrid 时,这就是它的样子... http://img405.yfrog.com/img405/5534/4192010102546am.png
如您所见,第一行的第一个单元格是白色的,因为它被选中了。
任何想法如何使它不选择第一行中的第一列?