Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancing DataGrid.RowStyle #4158

Closed
JLTook11 opened this issue Aug 3, 2021 · 4 comments
Closed

Enhancing DataGrid.RowStyle #4158

JLTook11 opened this issue Aug 3, 2021 · 4 comments

Comments

@JLTook11
Copy link

JLTook11 commented Aug 3, 2021

Similar to #1492 ?

The following works fine to change the Background when IsPlayer is True -- however, the other MahApps DataRow DataTriggers will no longer fire (e.g. row is selected or highlighted / mouse over). Not sure how to simply add this behavior without affecting any of the existing triggers -- and may or may not be specific to MahApps.

<DataGrid.RowStyle>
	<Style TargetType="DataGridRow"  BasedOn="{StaticResource MahApps.Styles.DataGridRow}">
		<Style.Triggers>
			<DataTrigger Binding="{Binding IsPlayer}" Value="true">
				<Setter Property="Background" Value="{StaticResource MahApps.Brushes.Accent4 }"></Setter>
			</DataTrigger>
		</Style.Triggers>
	</Style>
</DataGrid.RowStyle>

Thanks!

@timunie
Copy link
Collaborator

timunie commented Aug 4, 2021

Hi @JLTook11

I think the issue here is, that the original Triggers are overridden by your owns. You can try to copy&paste the original ones to your Style and see if it works for you:

<Style.Triggers>
<Trigger Property="IsNewItem" Value="True">
<Setter Property="Margin" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}, Path=NewItemMargin}" />
</Trigger>
<!-- IsSelected -->
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="mah:DataGridHelper.SelectionUnit" Value="FullRow" />
<Condition Property="IsSelected" Value="True" />
</MultiTrigger.Conditions>
<Setter Property="Background" Value="{DynamicResource MahApps.Brushes.DataGrid.Selection.Background}" />
<Setter Property="BorderBrush" Value="{DynamicResource MahApps.Brushes.DataGrid.Selection.BorderBrush}" />
<Setter Property="Foreground" Value="{DynamicResource MahApps.Brushes.DataGrid.Selection.Text}" />
</MultiTrigger>
<!-- IsSelected and Selector.IsSelectionActive -->
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="mah:DataGridHelper.SelectionUnit" Value="FullRow" />
<Condition Property="IsSelected" Value="True" />
<Condition Property="Selector.IsSelectionActive" Value="False" />
</MultiTrigger.Conditions>
<Setter Property="Background" Value="{DynamicResource MahApps.Brushes.DataGrid.Selection.Background.Inactive}" />
<Setter Property="BorderBrush" Value="{DynamicResource MahApps.Brushes.DataGrid.Selection.BorderBrush.Inactive}" />
<Setter Property="Foreground" Value="{DynamicResource MahApps.Brushes.DataGrid.Selection.Text.Inactive}" />
</MultiTrigger>
<!-- IsMouseOver -->
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="mah:DataGridHelper.SelectionUnit" Value="FullRow" />
<Condition Property="IsMouseOver" Value="True" />
</MultiTrigger.Conditions>
<Setter Property="Background" Value="{DynamicResource MahApps.Brushes.DataGrid.Selection.Background.MouseOver}" />
<Setter Property="BorderBrush" Value="{DynamicResource MahApps.Brushes.DataGrid.Selection.BorderBrush.MouseOver}" />
<Setter Property="Foreground" Value="{DynamicResource MahApps.Brushes.DataGrid.Selection.Text.MouseOver}" />
</MultiTrigger>
<!-- IsEnabled -->
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="mah:DataGridHelper.SelectionUnit" Value="FullRow" />
<Condition Property="IsEnabled" Value="False" />
</MultiTrigger.Conditions>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
</MultiTrigger>
<!-- IsEnabled and IsSelected -->
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="mah:DataGridHelper.SelectionUnit" Value="FullRow" />
<Condition Property="IsEnabled" Value="False" />
<Condition Property="IsSelected" Value="True" />
</MultiTrigger.Conditions>
<Setter Property="Background" Value="{DynamicResource MahApps.Brushes.DataGrid.Selection.Background.Disabled}" />
<Setter Property="BorderBrush" Value="{DynamicResource MahApps.Brushes.DataGrid.Selection.BorderBrush.Disabled}" />
<Setter Property="Foreground" Value="{DynamicResource MahApps.Brushes.DataGrid.Selection.Text.Disabled}" />
</MultiTrigger>
</Style.Triggers>

Happy coding
Tim

@JLTook11
Copy link
Author

JLTook11 commented Aug 4, 2021

Thanks, Tim -- that works!

Was hoping there was a way to just "add" to the existing triggers without overriding all of them -- the "BasedOn" does exactly this for all the other styling, but not the triggers. Guessing there may be a way to do this, but far exceeds my WPF expertise.

@timunie
Copy link
Collaborator

timunie commented Aug 4, 2021

I am not sure, at least I didn't find something. Moreover when there is such a concept it's not MahApps related. So please close this issue if it's solved for you 🙏

Thx
Tim

@JLTook11
Copy link
Author

JLTook11 commented Aug 6, 2021

Yes, mostly a WPF concept / issue (unless there was something the MahApps styles could change to make this possible).

Closing... thanks again!

@JLTook11 JLTook11 closed this as completed Aug 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants