You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

C#中RadioButton内容过长需换行的问题求助(附XAML代码)

解决WPF RadioButton内容换行问题

问题根源

你遇到的问题有两个核心点:

  • 直接给RadioButton的Content属性设置带
的字符串不会生效,因为默认的内容呈现器不解析换行符
  • 你给RadioButton固定了Height="20",就算内容能换行,高度也不够显示多行文本

两种可行解决方案

方案1:自动换行(推荐)

把RadioButton的Content换成TextBlock,开启自动换行,同时去掉固定高度(或设为Auto):

<RadioButton x:Name="RbMitarbeiterNicht" Grid.ColumnSpan="2"
             HorizontalAlignment="Left" Margin="863,929,0,0"
             VerticalAlignment="Top"
             GroupName="rb_stoerung"
             FontSize="16" Width="102" Foreground="#000000"
             Background="#FFFFFF" Checked="RbMitarbeiterNicht_Checked">
    <TextBlock Text="Mitarbeiter nicht anwesend" TextWrapping="Wrap"/>
</RadioButton>

这样文本会根据RadioButton的宽度自动换行,控件高度也会自适应内容。

方案2:手动指定换行位置

如果需要在特定位置换行,在TextBlock的文本里插入&#x0a;(或者直接在后台代码里用\n):

<RadioButton x:Name="RbMitarbeiterNicht" Grid.ColumnSpan="2"
             HorizontalAlignment="Left" Margin="863,929,0,0"
             VerticalAlignment="Top"
             GroupName="rb_stoerung"
             FontSize="16" Width="102" Foreground="#000000"
             Background="#FFFFFF" Checked="RbMitarbeiterNicht_Checked">
    <TextBlock Text="Mitarbeiter nicht&#x0a;anwesend" TextWrapping="Wrap"/>
</RadioButton>

关键注意事项

  • 必须去掉固定的Height="20",否则多行内容会被截断
  • 不要直接给RadioButton的Content属性设置带换行的字符串,必须用TextBlock这类支持换行的控件承载内容

内容的提问来源于stack exchange,提问作者Code123

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 00:25:13