views:

12

answers:

1

I want to creat my own control:

public class DataGrid : System.Windows.Controls.DataGrid

In the style definition, I want to add a button above the grid, so I wrote:

 <Style TargetType="local:DataGrid">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:DataGrid">
                 <Grid>
                    <Button Content="Addnew"></Button>
                    <?????>
                  </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
</Style>

But how can I tell the xaml to put the grid at postion ????? ?

Thank you all!!

A: 

Are you sure that you want to use inheritance here? You should consider creating another control that contains a DataGrid rather than inheriting from DataGrid and use the default Template.

If you decide that you do need to customize the Template of the DataGrid you will need to recreate the entire DataGrid template. You can find the original DataGrid template by opening the DataGrid's assembly in .net reflector or a similar application and opening the embedded resource "generic.xaml". This file will contain a ResourceDictionary defining all the default styles for the Controls defined in the assembly. You can copy the default Template from here and modify it as necessary.

Alternatively, if you have Expression Blend you can have it do this automatically by right clicking on the DataGrid control and choosing "edit a copy of this template" (or something like that, I can't remember the exact wording off the top of my head).

KeithMahoney