开发者

How to make DataGrid in Silverlight 4 show no selection?

I have a DataGrid that I want to simply display data in. I don't want anything to be selected. However, it always wants to select the first column of the first row.

Here is the 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>

and here is the code to populate the grid

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;
}

When the DataGrid is displayed, this is what it looks like... http://img405.yfrog.com/img405/5534/4192010102546am.png

As you can see, the first cell of the first row i开发者_运维知识库s white because it is selected.

Any ideas how to make it not selected the first column in the first row?


I've done this in the past by editing the control's templates so that the selected row looks just like an ordinary row

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜