Я пытаюсь встроить Radiobuttons в RichTextBox абзацах, но значения RadioButton ширина и высота не применяется:ControlTemplate FindAncestor связывания не работает
<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);
Вы пытались посмотреть в окне вывода? Существуют ли какие-либо ошибки привязки или предупреждения? – user2250152
Правильно, есть один: не удается найти источник для привязки со ссылкой 'RelativeSource FindAncestor, AncestorType =' System.Windows.Documents.Paragraph ', AncestorLevel =' 1 ''. BindingExpression: Path = Paragraph.Style.FontSize; DataItem = NULL; целевой элемент - «Grid» (Name = ''); target свойство 'Width' (тип 'Double') – Pollitzer