Trigger, Datatrigger - what's the difference?

Markus Freitag 3,791 Reputation points
2020-08-06T05:55:32.053+00:00

Hi ,
my goal is select the first row inside the Datagrid.
Works well with MoveCurrentToFirst.

Only if the control get the focus is it blue.
Is there a way to control it from the code?
And if the focus is the DataGrid, the default color is blue. How could I change this to light green?
You said triggers, yes, but where?

I can set a trigger for each control.
Is that right?

But I can also do it globally for each button. Is that right?

Where is the different? DataTrigger Binding="{Binding ElementName=txtScanMagazine,
Trigger Property="PropertyToCheck" Value="CheckValue">

PropertyToCheck is my own function?
Value is the return value?

16032--where-is-the-right-place.png

15967--where-is-the-right-place2.png

15968--where-is-the-right-place3.png

Developer technologies Windows Presentation Foundation
0 comments No comments
{count} votes

Accepted answer
  1. DaisyTian-1203 11,646 Reputation points
    2020-08-06T08:55:29.083+00:00

    Add the below code for your DataGrid:

        <DataGrid.Resources>  
                        <SolidColorBrush x:Key="columnBackground"/>  
        </DataGrid.Resources>  
    

    Then set the CellStyle for the DataGrid:
    16105-capture.png

    Change the color in the cs:

    this.dg.Resources["columnBackground"] = Brushes.Red;

    The result is like below shown:
    16036-4.gif

    Here is the demo code for you to test.

    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. DaisyTian-1203 11,646 Reputation points
    2020-08-06T07:21:03.857+00:00

    You need to set trigger under the Style/Style.Triggers.Such as the using of Triggers:
    16004-capture.png

    There are several different types of triggers: Trigger, MultiTrigger, EventTrigger, DataTrigger, and MultiDataTrigger. In the document , you can see the examples of how to use Trigger and EventTrigger.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.