Larsi
Larsi

Reputation: 4774

Add Effect to some of the rows in a DataGrid

This is what I want: When user clicks a button, all rows that meets a criteria should have a Blur effect added

Problem: The only way I've found to do this is in the LoadingRow event. But in my case the row is already loaded when I want to apply the Blur Effect.

Question: How to iterate over rows so that I can apply the Blur effect. Or, even better, how can I bind a Effect to a row?

This is my code that only works when applying effect on startup:

    private void dg_LoadingRow(object sender, DataGridRowEventArgs e)
    {
        if (true) // Logic for figuring out if a row should be blur'ed
            e.Row.Effect = new BlurEffect { Radius = 8 };
    }

Thanks for any help

Larsi

Upvotes: 2

Views: 385

Answers (1)

Larsi
Larsi

Reputation: 4774

I found a solution to this:

Bind to the Effect property on the DataGridCellPresenter like this:

<sdk:DataGridCellsPresenter x:Name="CellsPresenter" Grid.Column="1" sdk:DataGridFrozenGrid.IsFrozen="True" Effect="{Binding ., Converter={StaticResource BlurConverter}}"/>

And the converter simply:

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
    // Some logic...
    return new BlurEffect { Radius = 8 }; 
}

Lars Erik

Upvotes: 1

Related Questions