开发者

WPF DataGrid: Cancel the first row selection by default

In my DataGrid the first row becomes selected by default. How can I cancel this?

<Window x:Class="WpfApplication50.Window7"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:dg="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit" 
   开发者_如何学C Title="Window7" SizeToContent="WidthAndHeight">
<Window.Resources>
    <!--Data-->
    <XmlDataProvider x:Key="MyData" XPath="/Info">
        <x:XData>
            <Info xmlns="">
                <Item ID="ISBN 45-F1" Name="Winner" Price="$32.05" Author="Aka" Catalog="Business"/>
                <Item ID="ISBN 54-32" Name="C++ Inside" Price="$10.00" Author="John" Catalog="Language"/>
                <Item ID="ISBN 14-A0" Name="Java Inside" Price="$9.00" Author="Tom" Catalog="Language"/>
                <Item ID="ISBN 56-78" Name="Stock Market" Price="$8.50" Author="Bob" Catalog="Business"/>
                <Item ID="ISBN AA-02" Name="Guideline for Health" Price="$19.00" Author="Lee" Catalog="Health"/>
                <Item ID="ISBN A4-07" Name="C# Inside" Price="$8.50" Author="Bob" Catalog="Language"/>
            </Info>
        </x:XData>
    </XmlDataProvider>
    <CollectionViewSource x:Key='src' Source="{Binding Source={StaticResource MyData}, XPath=Item}">
        <CollectionViewSource.GroupDescriptions>
            <PropertyGroupDescription PropertyName="@Catalog"/>
        </CollectionViewSource.GroupDescriptions>
    </CollectionViewSource>
    <!--Data-->
</Window.Resources>
<Grid>
    <dg:DataGrid
     AutoGenerateColumns="False"
     Background="White" IsReadOnly="True" Padding="0" Margin="0"
     BorderThickness="0"
     GridLinesVisibility="None"
     HorizontalScrollBarVisibility="Disabled"
        HeadersVisibility="All"
     ItemsSource='{Binding Source={StaticResource src}}'
     SelectionMode="Single"    
     SelectionUnit="FullRow"
     VerticalGridLinesBrush="DarkGray"
     VerticalScrollBarVisibility="Disabled">
        <dg:DataGrid.Columns>
            <dg:DataGridTextColumn Binding="{Binding XPath=@ID}" Header="ID"/>
            <dg:DataGridTextColumn Binding="{Binding XPath=@Name}" Header="Name"/>
            <dg:DataGridTextColumn Binding="{Binding XPath=@Price}" Header="Price"/>
            <dg:DataGridTextColumn Binding="{Binding XPath=@id}" Header="Author"/>
        </dg:DataGrid.Columns>

    </dg:DataGrid>
</Grid>


xaml:


 <dg:DataGrid Name="SC_dgList"  CanUserAddRows="False" Loaded="SC_dgList_Loaded">

cs:

private void SC_dgList_Loaded(object sender, RoutedEventArgs e)
 {
      SC_dgList.SelectedIndex = -1;
 }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜