How is inheritance accomplished in XAML?
Is it true that only the code-behind can be inherited and not the .xaml (related question)? Is including the parent in the child control's namespace the only way of doing it?
There seems to be no general "inheritance" per se in XAML. There are questions about inheriting UserControl
, etc. but not general inheritance.
Problem:
I have 2 xaml files, File1.xaml
and File2.xaml
, which are very alike. Can I create a SuperFile.xaml
and put the bulk of the following code in it?
<UserControl ... >
<Grid>
<Grid.RowDefinitions ... />
<DockPanel ... >
<ToolBar ... >
<!-- Some Buttons here:
File1.xaml to contain the Buttons "View" and "Export"
File2.xaml to contain the Buttons "Edit" and "Delete"
-->
</ToolBar>
</DockPanel>
<igDP:XamDataGrid MouseDoubleClick="xamDataGrid1_MouseDoubleClick" ... />
</Grid>
</UserControl>
The only things that differ in File1.xaml
and File2.xaml
are:
Button
s in theToolBar
(see comment in the code)- The properties of
XamDataGrid
, primarily the events (what they do in each case).
How can I achieve this? Would I have to write the code-behind files for both the children separately?