How do I force UserControls in WPF that are inside a ToolBar to use the ToolBar's default button style?
I have a simple user control called ImageButton which has XAML something like this:
<UserControl x:Class="myNameSpace.ImageButtonUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="imageButton"
>
<Button Style="{Binding ElementName=imageButton, Path=ButtonStyle}">
<StackPanel Orientation="Horizontal">
<Image Source="{Binding ElementName=imageButton, Path=ImageSource}"
VerticalAlignment="Center"
/>
<TextBlock Text="{Binding ElementName=imageButton, Path=Text}"
Style="{Binding ElementName=imageButton, Path=TextStyle}"
VerticalAlignment="Center"
/>
</StackPanel>
</Button>
</UserControl>
I have some dependency properties in the code behind for those binding paths and everything works fine.
That is until I put it in a ToolBar. Normally when you put buttons in a ToolBar they are restyled by the ToolBar to look like toolbar buttons. I've found out how I can change this style (see ToolBar.ButtonStyleKey. But how can I apply the already defined style to my User Control's Button Style dependency property?