我正在尝试使用下面的xaml定义一个Button:
下面的标记为我提供了图像和文字,但不作为加速键(“_”不隐藏,Alt-A不起作用)。
如何修复标记以获取加速键功能?
当前的标记和行为
<Style x:Key="AddNewItemButtonStyle" BasedOn="{StaticResource blueButtonStyle}" TargetType="{x:Type Button}">
<Setter Property="Content">
<Setter.Value>
<StackPanel Orientation="Horizontal" >
<Image Source="{resx:Resx ResxName=Presentation.Resources.MasterDetail, Key=bullet_add}" Stretch="Uniform" />
<TextBlock Text="_"/>
<TextBlock Text="{resx:Resx ResxName=Presentation.Resources.MasterDetail, Key=Subject_AddNew}" />
<TextBlock Text=" "/>
<TextBlock Text="{Binding Subject}" />
</StackPanel>
</Setter.Value>
</Setter>
<Setter Property="Command" Value="{Binding AddNewItemCommand}" />
</Style>
没什么但是图像:
<Style x:Key="AddNewItemButtonStyle" BasedOn="{StaticResource blueButtonStyle}" TargetType="{x:Type Button}">
<Setter Property="Content" >
<Setter.Value>
<MultiBinding StringFormat="_{0} {1} {2}">
<Binding Source="{resx:Resx ResxName=Presentation.Resources.MasterDetail, Key=Add}"/>
<Binding Source="{resx:Resx ResxName=Presentation.Resources.MasterDetail, Key=New}"/>
<Binding Path="Subject"/>
</MultiBinding>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<StackPanel Orientation="Horizontal">
<Image Source="{resx:Resx ResxName=Presentation.Resources.MasterDetail, Key=bullet_add}" Stretch="Uniform" />
<ContentPresenter/>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Command" Value="{Binding AddNewItemCommand}" />
</Style>
答案 0 :(得分:1)
答案 1 :(得分:1)
您可以将AccessText与多重绑定一起使用
<Style x:Key="AddNewItemButtonStyle" TargetType="{x:Type Button}">
<Setter Property="Content">
<Setter.Value>
<StackPanel Orientation="Horizontal" >
<Image Source="{... your image}" Stretch="Uniform" />
<AccessText>
<AccessText.Text>
<MultiBinding StringFormat="{}_{0} {1}">
<Binding Source="{... resources}"/>
<Binding Source="{Binding Subject}"/>
</MultiBinding>
</AccessText.Text>
</AccessText>
</StackPanel>
</Setter.Value>
</Setter>
</Style>
答案 2 :(得分:1)
尝试使用Label控件。它专为你有两个控件的情况而设计,一个控件有一个用于触发第二个控件的访问键。
答案 3 :(得分:0)
您需要将Content
设置为组合文本,而无法在模板中完成。
<!-- (Resources changed for testing) -->
<Style TargetType="Button">
<Setter Property="Content">
<Setter.Value>
<MultiBinding StringFormat="_{0} {1}">
<Binding Source="{StaticResource Res_Add}"/>
<Binding Path="Subject"/>
</MultiBinding>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<StackPanel Orientation="Horizontal">
<Image Source="{StaticResource Res_Image}" Stretch="Uniform"/>
<ContentPresenter/>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>