是否可以将一个或多个控件基于资源中定义的控件。以便控件从基本控件继承大多数属性。类似于 Style 方法,但由于某种原因我不能使用 Events/EventSetter(AutoGeneratingColumns
在这种情况下),我得到的错误是“xy-Event 不是路由事件”
这是我想要完成的一个例子。我有大多数属性相同的数据网格
<DataGrid x:Name="gridEditSystem"
AutoGeneratingColumn="onGridEditSystem_autoGeneratingColumn"
SelectionUnit="Cell"
SelectionMode="Single" CellStyle="{StaticResource GridEditStyle}">
</DataGrid>
<DataGrid x:Name="gridEditPlanets" SelectedCellsChanged="gridEditPlanets_SelectedCellsChanged"
AutoGeneratingColumn="onGridEditSystem_autoGeneratingColumn"
SelectionUnit="Cell"
SelectionMode="Single" CellStyle="{StaticResource GridEditStyle}">
</DataGrid>
我现在想要的是“基本控制”
<Window.Resources>
<DataGrid x:Key="BaseDataGrid" AutoGeneratingColumn="onGridEditSystem_autoGeneratingColumn"
SelectionMode="Single" SelectionUnit="Cell"
CellStyle="{StaticResource GridEditStyle}">
</DataGrid>
</Window.Resources>
并继承 Controls
<DataGrid x:Name="gridEditSystem"
BasedOn/Inherits/Templates={StaticResource BaseDataGrid}
</DataGrid>
<DataGrid x:Name="gridEditPlanets"
BasedOn/Inherits/Templates={StaticResource BaseDataGrid}
</DataGrid>
我尝试了一些组合,但到目前为止都失败了,也没有在谷歌上找到任何东西。这在 XAML 中可能吗?