views:

19

answers:

1
+1  Q: 

extend a control

Hi

In regular C#, if i want to extend my class, i inherit from the base one and add my class. I have a XAML UserControl, i want to add a new functionnality. For instance, i have a DataGrid, and i want to add a Contextmenu that allows to user to print.

I don't quite see how should i inherit from the the usercontrol ?

thanks Jon

+1  A: 

In the code behind (ChildControl.xaml.cs), you simply extend the class as you would do in WinForms.

Then in XAML:

<local:BaseClassName
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:YourNamespaceName"  
mc:Ignorable="d"
x:Class="ChildControlClassName"
x:Name="ChildControlName"
d:DesignWidth="640" 
d:DesignHeight="480" 
>
    ...control XAML
</local:BaseClassName>

In your example woth the DataGrid, you would add the DataGrid into the control XAML, and set its ContextMenu property.

CommanderZ