如何强制WPF中的ToolController中的UserControl使用ToolBar的默认按钮样式?使ToolBar按钮样式适用于工具栏中的UserControls
我有具有XAML是这样叫的ImageButton一个简单的用户控件:
<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中。通常,当你将按钮放在ToolBar中时,它们会被ToolBar重新设置为看起来像工具栏按钮。我已经发现如何改变这种风格(请参阅ToolBar.ButtonStyleKey。但是我怎样才能将已定义的风格应用到我的用户控件的按钮样式依赖项属性?
我不想自动创建一个,我只想将现有的按钮样式应用到我的UserControl中的按钮。 – Ray 2009-06-03 23:00:34