【发布时间】:2014-10-24 06:42:05
【问题描述】:
我是 WPF 的新手。我在 WPF 应用程序的菜单中有单选按钮列表。我将单选按钮的样式更改为看起来像文本块作为子菜单。现在的问题是,当我尝试在单选按钮内包装图像和文本时,它没有显示出来。但是如果我删除了我在单选按钮上添加的样式,使其看起来和感觉像文本块,那么包装就可以正常工作,但是它会显示我不需要的单选按钮图标。
请参考以下代码:
<StackPanel.Resources>
<Style x:Key="RadioButtonMenuStyle" TargetType="RadioButton">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RadioButton}">
<TextBlock Text="{TemplateBinding Content}">
<TextBlock.Style>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Height" Value="36"/>
<Setter Property="Foreground" Value="Black" />
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="TextAlignment" Value="Center"/>
<Setter Property="TextWrapping" Value="Wrap"/>
</TextBlock.Style>
</TextBlock>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</StackPanel.Resources>
------------------------------------------------------------------------
<RadioButton Name="rbttest" GroupName="rbtgroup" Background="{x:Null}" Style="
{StaticResource RadioButtonMenuStyle}" IsChecked="True">
<WrapPanel>
<Image Source="/WpfApplication1;component/Images/Test.ico" Width="16" Height="16"
Margin="0,0,5,0" />
<TextBlock Text="Test" Foreground="Green" />
</WrapPanel>
</RadioButton>
是模板绑定内容导致问题吗?
【问题讨论】: