图中红色的模块为RadioButton内容和默认样式
修改后
控件代码
<RadioButton>
<DockPanel LastChildFill="False">
<TextBlock Text="" FontFamily="./Fonts/#iconfont" VerticalAlignment="Center"></TextBlock>
<TextBlock Text="我的一天" Margin="15 0 0 0"></TextBlock>
<TextBlock Text="1" DockPanel.Dock="Right" ></TextBlock>
</DockPanel>
</RadioButton>
样式代码
<Style TargetType="RadioButton">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RadioButton}">
<Grid>
<ContentPresenter></ContentPresenter>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
样式代码理解(知其所以然)
<Style TargetType="RadioButton">
1.这定义了一个样式,该样式针对所有RadioButton控件。
<Setter Property="Template">
2.设置一个属性模板,用于修改默认样式。
<Setter.Value>
3.模板值,对应Property。
<ControlTemplate TargetType="{x:Type RadioButton}">
4.定义了一个新的模板,该模板是专门为RadioButton控件设计的。
<Grid>
<ContentPresenter></ContentPresenter>
</Grid>
5.用Grid布局,用ContentPresentr只显示内容
AI解释(我觉得很有道理就没去翻文档)
<ContentPresenter></ContentPresenter>
这个标签只是简单地呈现内容,而不负责呈现选中状态或控件的修饰元素。在默认的RadioButton模板中,圆圈表示该单选按钮是否被选中。当您重写模板并只使用ContentPresenter时,您实际上是在移除与选中状态相关的所有视觉效果,因此不会显示圆圈。
如果您希望保留圆圈或其他控件修饰,您需要在模板中添加相应的元素和逻辑来显示它们。例如,您可以使用RadioButton的Checked和Unchecked事件来动态更改内容呈现器或其他视觉元素,以反映其选中状态。
注:跟着UP学习的,视频没有解释的很清楚,自己去了解作为记录 链接