2
votes

I have this problem:

I have an user control which contains: 1) A DataGrid

<DataGrid   x:Name="GrdHistoricalInformation"
            Style="{StaticResource BaseDataGridStyle}"
            SelectedIndex="0"
            ItemsSource="{Binding BarList}"                  
            HorizontalScrollBarVisibility="Auto"  
            BorderThickness="1" 
            BorderBrush="Black" 
            HorizontalAlignment="Stretch"
            CanUserSortColumns="False"
            DockPanel.Dock="Top"
            ColumnHeaderHeight="50"
            SelectedItem="{Binding SelectedBar, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">

2) An user control with some radiobuttons that have a command that fires on my viewmodel.

My problem is that when i select a row and then i press a radiobutton, the selected item on the grid loses the "highlight" (Even though I have the selected item binded correctly in my viewmodel)

Here I select a row: 1

Then when i press the RB loses focus

enter image description here

And i am not able to use events on the solution because of the mvvm pattern.

Any suggestion or help will be very much appretiated! Thanks in advance.

EDITED:

Tried with this style:

<Style.Triggers>
    <MultiTrigger>
        <MultiTrigger.Conditions>
            <Condition Property="IsSelected" Value="True" />
            <Condition Property="Selector.IsSelectionActive" Value="False" />
        </MultiTrigger.Conditions>
        <Setter Property="Background" Value="#660066"/>
    </MultiTrigger>
</Style.Triggers>

But still not working.

2

2 Answers

2
votes

Try this instead:

<DataGrid.CellStyle>
    <Style TargetType="DataGridCell">
        <Style.Triggers>
            <Trigger Property="IsSelected" Value="True">
                <Setter Property="Background" Value="#660066" />
                <Setter Property="BorderBrush" Value="#660066" />
            </Trigger>
        </Style.Triggers>
    </Style>
</DataGrid.CellStyle>
1
votes

The DataGridRow has 2 visual states for that: Normal_Selected and Unfocused_Selected. It seems your style does not define any colors in Unfocused_Selected.