我该如何强制WPF中位于工具栏内的UserControl使用工具栏默认按钮样式?
我有一个简单的名为ImageButton的用户控件,其XAML大致如下:
我在代码后端有一些依赖属性,用于绑定路径,一切都运作正常。但是当我把它放在工具栏中时就出问题了。通常情况下,当您将按钮放入工具栏中时,工具栏会重新设计它们以使其看起来像工具栏按钮。我已经找到了如何更改此样式的方法(请参见ToolBar.ButtonStyleKey)。但是,我如何将已定义的样式应用于我的用户控件的Button Style依赖属性?
我有一个简单的名为ImageButton的用户控件,其XAML大致如下:
<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>
我在代码后端有一些依赖属性,用于绑定路径,一切都运作正常。但是当我把它放在工具栏中时就出问题了。通常情况下,当您将按钮放入工具栏中时,工具栏会重新设计它们以使其看起来像工具栏按钮。我已经找到了如何更改此样式的方法(请参见ToolBar.ButtonStyleKey)。但是,我如何将已定义的样式应用于我的用户控件的Button Style依赖属性?