Custom DataGrid class, style doesn't get inherited...

Nov 7, 2013 at 11:43 AM
Hi!

First of all I really like the look of the <m:ui/>!!

Not sure if this is the right place to post this question but I'll give it a try.
I would like to create my own DataGrid (adding some context menu on right mouse click etc).
When I create a class similar to the one below

...
public class MyDataGrid : DataGrid
{
//Do some nice extra features to the original data grid but not yet implemented
}
and uses it in a wpf page, the styling from the original m:ui data grid isn't applied. I receive a grey background of the grid as well as some vertical gridlines.

How do I use the style from the original data grid in a simple manner?

I have tried to do something similar to (just for testing)
<Style TargetType="{x:Type uc:MyDataGrid}" BasedOn="{StaticResource {x:Type DataGrid}}">
        <Setter Property="Background" Value="Black"/>
    </Style>
But the style isn't applied for the MyDataGrid.

Any idea of what I'm doing wrong?

Thanks'
/Andreas
Feb 28, 2014 at 7:47 PM
Hi

I do not know if issue was solved, I see it's quite old.
Have a look here http://stackoverflow.com/questions/6780605/how-to-make-a-wpf-style-inheritable-to-derived-classes.
I took the last solution (for some reason the first 2 did not work), this meaning:

public class MyDataGrid : DataGrid
{
    public MyDataGrid() : base()
    {
        this.SetResourceReference(StyleProperty, typeof(DataGrid));
    }
//Do some nice extra features to the original data grid but not yet implemented
}