Style determined by code behind variable

Jul 1, 2009 at 4:27 PM

I want to highlight the rows in a datagrid based on whether a cell in the row (userID) is equal to the current user (codeBehindUser)
I don't seem to be able to use a DynamicResource as a DataTrigger Value.
I'd be very grateful to know how (if) this can be achieved.
e.g:
public partial class Window1 : Window
{
int codeBehindUser=1;
}
           <Style.Triggers>
                <DataTrigger Binding="{Binding Path=userID}" Value=codeBehindUser>
                   <Setter Property="Foreground" Value="Red"></Setter>
                </DataTrigger>
            </Style.Triggers>

Jul 3, 2009 at 2:40 AM

Not a pro myself but maybe you could do something like:

add a field to the dataset or whatever you are using as the Items Source for the grid.

Store the highlight value in the field.

Bind the field to the highlight property of the rows - whether the color you want to use or whatever you are using to highlight the row.

E.g. in the XAML above where you have Value=Red, instead of Red, you can bind that value to the field in your data source. 

Then when the field changes, the foreground color will change too.

Hope this helps.