В итоге я реализовал это с помощью приведенного ниже свойства зависимостей и ItemsControl в моем шаблоне:
public static readonly DependencyProperty ActionsProperty =
DependencyProperty.Register("Actions", typeof(ObservableCollection<UIElement>), typeof(ModalWindow), new UIPropertyMetadata(new ObservableCollection<UIElement>()));
public ObservableCollection<UIElement> Actions
{
get => (ObservableCollection<UIElement>)GetValue(ActionsProperty);
set => SetValue(ActionsProperty, value);
}
<ItemsControl Grid.Row="1" ItemsSource="{TemplateBinding Actions}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
Использование:
<BaseView.Actions>
<Button>Action 1</Button>
<Button>Action 2</Button>
</BaseView.Actions>
Я думаю, что UIElementCollection
было бы лучше подходит для типа свойства, но я не уверен, как создать экземпляр этой коллекции с необходимыми параметрами.