Skip to content
New issue

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

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

Already on GitHub? # to your account

Datagrid TextColumn does not get styled #3667

Closed
timunie opened this issue Oct 30, 2019 · 2 comments · Fixed by #3672
Closed

Datagrid TextColumn does not get styled #3667

timunie opened this issue Oct 30, 2019 · 2 comments · Fixed by #3672
Assignees
Labels
Milestone

Comments

@timunie
Copy link
Collaborator

timunie commented Oct 30, 2019

Describe the bug
the DataGridTextColumn does not get stlyed in the editing mode.

To Reproduce
Have a look at the demo app
image
image

Expected behavior
the TexBox and its ContextMenu should be styled according to the selected theme

Screenshots
see above

Environment(please complete the following information):

  • MahApps.Metro version latest alpha
  • OS: Windows 7
  • Visual Studio 2019
  • .NET Framework tested with different

Happy coding
Tim

@punker76
Copy link
Member

@timunie This doesn't work in v1.6.5 either.

@timunie
Copy link
Collaborator Author

timunie commented Oct 31, 2019

@punker76 I had a deeper look into this. The EditingElement is a TextBox based on the default Windows TextBox. But we can set our own Style by setting:

<DataGridTextColumn Binding="{Binding Title}"
                    EditingElementStyle="{StaticResource MahApps.Styles.TextBox.Borderless}"
                    Header="Title" />

unfortunatally one has to set this manually because you cannot have a Style for DataGridTextColumn 😞 because M 💲 does not support this.

I see two ways:

  1. Provide a Style e.g. MahApps.Styles.TextBox.Borderless and let the user implement it on every DataGridTextColumn

  2. Having an AttachedProperty for DataGrid which catches the PreparingCellForEdit event:

private void DataGrid_PreparingCellForEdit(object sender, DataGridPreparingCellForEditEventArgs e)
{
    if (e.EditingElement is TextBox textBox && Application.Current.TryFindResource("MahApps.Styles.TextBox.Borderless") is Style style)
    {
        textBox.SetCurrentValue(TextBox.StyleProperty, style);
    }
}

The result would look like this:
DataGrid_ContextMenu

What do you think which way we should go?

@timunie timunie changed the title Datagrid Contextmenu is broken in latest alpha Datagrid TextColumn does not get styled Oct 31, 2019
@punker76 punker76 added the Bug label Nov 3, 2019
@punker76 punker76 self-assigned this Nov 3, 2019
@punker76 punker76 added this to the 2.0.0 milestone Nov 3, 2019
punker76 added a commit that referenced this issue Nov 3, 2019
- Add new TextBox editing style `MahApps.Styles.TextBox.DataGrid.Editing`
amkuchta pushed a commit to amkuchta/MahApps.Metro that referenced this issue Nov 19, 2019
- Add new TextBox editing style `MahApps.Styles.TextBox.DataGrid.Editing`
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants