我能否在WPF中将单选按钮的内容/文本值包装起来?

8

我有一些XAML代码:

<StackPanel Orientation="Horizontal">
    <TextBlock x:Name="KeyLWP" TextWrapping="Wrap" MaxWidth="120">A Letter or Word or Phrase
    </TextBlock>
    <StackPanel>
        <RadioButton x:Name="rdbtnCandidateVal1" Content="Two wrongs don't make a Wright Brothers Grimm was the Thingamabob Dylan Thomas Jefferson Airplane">
        </RadioButton>

...在 RadioButton 的 Content 中分配了一个很长的字符串时,它会简单地从边缘掉落。我如何使其自动换行(必要时),就像 TextBlock 的 TextWrapping 和 MaxWidth 属性一样?还是必须将每个 RadioButton 与 TextBlock 配对,避免使用 RadioButton 的 Content/Text 属性?

1个回答

15

你有几个选项,你可以将其制作成单选按钮样式模板,以便适用于所有单选按钮,或者在实例级别上快速完成;

<RadioButton>
   <RadioButton.Content>
      <TextBlock Text="Wrap My Content Pretty Pretty Please" TextWrapping="Wrap"/>
   </RadioButton.Content>
</RadioButton>

还有其他选项,如果有具体情况,请告诉我,我们会帮你解决。


1
谢谢,Chris;我还得添加一个MaxWidth值,但那很容易。 - B. Clay Shannon-B. Crow Raven

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接