Greetings,
1. I have a datagrid which I am binding programatically a data set from an sql database.
this.dataGrid1.ItemsSource = dsData.Tables[0].DefaultView;
this.dataGrid1.DataContext = dsData.Tables[0];
dataGrid1.SelectedIndex = 0;
2. In my xaml I have a trigger which I am changing the color based upon if the cell is selected or not.
<DataGrid Visibility="Visible" ScrollViewer.IsDeferredScrollingEnabled="True" VerticalScrollBarVisibility="Hidden" Name="dataGrid1"
CanUserAddRows="False" CanUserResizeRows="False" CanUserDeleteRows="False" AutoGenerateColumns="False" GridLinesVisibility="None" HeadersVisibility="Column" FontSize="16.333" RowHeaderWidth="0"
IsReadOnly="True" SelectionMode="Single" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="Auto" Height="Auto" ColumnHeaderStyle="{StaticResource detailsColumnHeaderStyle}"
Focusable="False" SelectionChanged="dataGrid1_SelectionChanged" IsManipulationEnabled="False" >
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="White"
/>
<Setter Property="Foreground" Value="Black"
/>
<Setter Property="BorderThickness"
Value="0" />
</Trigger>
<Trigger Property="IsSelected" Value="False">
<Setter Property="Background" Value="White"
/>
<Setter Property="Foreground" Value="Black"
/>
<Setter Property="BorderThickness"
Value="0" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
</DataGrid>
3. It works fine when I do a mouse click on it, and it changes the colors great, BUT the issue is that when I set the datarow to position 0 at the time the datagrid loads the "trigger" from the xaml doesn't get issued. Instead it never performs the color change unless I actually click on the cell.
I am not sure what approach to take on this since I have tried setting it when the datagrid loads, and it doesn't seem to make a difference.
Thanks for any suggestions!