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

Allow for conditional style classes in DataGridTemplateColumn.CellStyleClasses to style cells individually based on a data binding #17807

Open
s-sarunas opened this issue Dec 19, 2024 · 0 comments

Comments

@s-sarunas
Copy link

Is your feature request related to a problem? Please describe.

It doesn't seem possible to add conditional style classes to the DataGridTemplateColumn.CellStyleClasses property in a DataGrid:

<DataGridTemplateColumn.CellStyleClasses>
    <Classes>
        <!--<Class Binding={...}-->
    </Classes>
</DataGridTemplateColumn.CellStyleClasses>

This would allow cells within a column to be styled differently based on a binding, e.g. disabling them.

Describe the solution you'd like

Allow to assign conditonal style classes on all DataGrid cells of that column:

<DataGridTemplateColumn.CellStyleClasses>
    <Classes>
        <!--<Class Binding={...}-->
    </Classes>
</DataGridTemplateColumn.CellStyleClasses>

Similar to conditional style classes for other controls:

<Button Classes.accent="{Binding IsSpecial}" />

Describe alternatives you've considered

It's possible to disable cells of a column when binding to the IsEnabled property of DataGridCell:

<ControlTheme x:Key="ControlThemeName"
              TargetType="{x:Type DataGridCell}"
              BasedOn="{StaticResource {x:Type DataGridCell}}">
    <Setter Property="IsEnabled"
            Value="{Binding Property}" />
</ControlTheme>

<Style Selector="DataGridCell[IsEnabled=False]">
    <Setter Property="Background"
            Value="Red" />
</Style>

<DataGridTemplateColumn CellTheme="{StaticResource ControlThemeName}">

While multiple conditions can be combined and bound to IsEnabled property with a MultiBinding, there's no way to style the DataGridCells differently (in my case to add a tooltip).

I have tried using a behavior on the DataGridTemplateColumn similar to the following example: https://github.com/wieslawsoltes/Avalonia.Xaml.Behaviors/blob/master/samples/BehaviorsTestApplication/Views/Pages/AddRemoveClassActionView.axaml

However, I don't think there's a way to reference the DataGridCell or the DataGridRow from within a DataGridTemplateColumn using a relative binding.

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant