Alexandru Dicu
Alexandru Dicu

Reputation: 1225

WPF DataGrid crash on cell click

I have a simple window with a simple DataGrid on it. The window has a ViewModel which contains a public property ObservableCollection that I use for binding the ItemsSource. This is the code that I use. Very, very basic.

PluginsView pv = new PluginsView();
pv.ShowDialog();

This is the XAML of my DataGrid which gets populated. I have tried also with Mode=TwoWay without any luck.

<DataGrid AutoGenerateColumns="False" ItemsSource="{Binding Plugins}"               
   <DataGrid.Columns>
      <DataGridTextColumn Binding="{Binding Name}" Header="Name"/>
      <DataGridTextColumn Binding="{Binding DllName}" Header="DllName"/>
   </DataGrid.Columns>
</DataGrid>

When I click on a cell to edit the data, I receive the following error and my program crashes. I don't use any styles. Everything is default. It crashes on pv.ShowDialog(); line.

Cannot set OverridesDefaultStyle property in the default Style.

I have tried anything that I know, but I can't solve this error. Can you please share some suggestions to try because this is getting ridiculous. Thank you.

Upvotes: 0

Views: 1877

Answers (1)

Alexandru Dicu
Alexandru Dicu

Reputation: 1225

I have found the problem. I had a global style for TextBox and when I was clicking on a datagrid cell, it tried to override the TextBox style of the DataGrid cell with the global one, causing that exception. Two days of work lost with this problem. SOLVED by setting a Key to the global style.

Upvotes: 3

Related Questions