0
votes

I'm having some trouble with subclassing and overriding WPFToolkit DataGrid events within a custom WPF Control. This is all for WPF on .NET Framework 3.5

My XAML is similar to the following

<UserControl x:Class="MyGUI.EM.DocChecklistView"
    xmlns:toolkit="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit">

<Grid>
        <toolkit:DataGrid  ItemsSource="{Binding Source={StaticResource DocVS}}" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" Name="_dgDoc" Margin="0,0,0,46">

The code is something similar to

public partial class DocChecklistView:  UserControl, IDataModuleView {     

        protected override System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
        {
            return null;
        }

        public CDocumentChecklistView() {
            InitializeComponent();
        }

However, note the first override in the code - that never fires. That makes sense since I'm not subclassing the DataGrid (WPFToolkit). How can I modify this code to include a subclass to the DataGrid and make sure the override fires???

1

1 Answers

1
votes

You can create a custom DataGrid control.

public class CustomDataGrid:  DataGrid
{   
    protected override System.Windows.Automation.Peers.AutomationPeer OnCreateAutomationPeer()
    {
        return null;
    }
}

Then you use that control in your view instead of the DataGrid.

<UserControl x:Class="MyGUI.EM.DocChecklistView"
    xmlns:toolkit="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
    xmlns:yourControl="clr-namespace:YourNamespace">

    <Grid>
        <yourControl:CustomDataGrid  ItemsSource="{Binding Source={StaticResource DocVS}}" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" Name="_dgDoc" Margin="0,0,0,46">