我正在尝试将 RadioButtons 嵌入 RichTextBox 段落中,但未应用 RadioButton 的宽度和高度值:
<Style x:Key="styleRb" TargetType="{x:Type RadioButton}">
<Setter Property="Focusable" Value="False"></Setter>
<Setter Property="Margin" Value="3,0,3,-1"></Setter>
<Setter Property="Padding" Value="0,0,0,0"></Setter>
<Setter Property="HorizontalAlignment" Value="Center"></Setter>
<Setter Property="VerticalAlignment" Value="Center"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RadioButton}">
<BulletDecorator Background="Transparent">
<BulletDecorator.Bullet>
<!--Values are applied:-->
<!--<Grid Width="13" Height="13">-->
<!--Values are not applied:-->
<Grid Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Paragraph}},
Path=FontSize}"
Height="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Paragraph}},
Path=FontSize}">
<Ellipse Stroke="Black" StrokeThickness="2.0"
Fill="Gold" Opacity="1.0">
</Ellipse>
</Grid>
</BulletDecorator.Bullet>
</BulletDecorator>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
嵌入代码是这样的:
RadioButton rb = new RadioButton();
rb.Style = (Style)Application.Current.FindResource("styleRb");
InlineUIContainer container = new InlineUIContainer(rb, rtbInsertionPosition);