我怎样才能让一个圆角?

时间:2015-10-27 12:20:03

标签: c# wpf border paragraph

我有一个富文本框,我将段落添加到(dynamiclly), 当我添加它们时,我想让段落边界成圆形,我该怎么做? 这是我的代码:

    <Grid>
    <RichTextBox x:Name="richTextBox" HorizontalAlignment="Left" Height="315" Margin="10,10,0,0" VerticalAlignment="Top" Width="312" IsReadOnly="True" >
        <FlowDocument x:Name="flowDocument" >

        </FlowDocument>
    </RichTextBox>
</Grid>

我尝试访问段落边框属性,但我无法做到。
我的代码中有这样的东西:

Paragraph p = new Paragraph(new Run("Some text"));
p.BorderBrush = Brushes.Black;
p.BorderThickness = new Thickness(1);
//Make the paragraph border round
flowDoucment.Blocks.Add(p);

我知道如何设置边框CornerRadius属性?

2 个答案:

答案 0 :(得分:2)

您可以使用BlockUIContainer并在其中再添加一个RichTextBox来实现它。请参阅下面的代码。

<RichTextBox>
        <FlowDocument>  
            <BlockUIContainer>
                <Border BorderThickness="2" BorderBrush="Blue" CornerRadius="8" Padding="3"> 
                    <RichTextBox  BorderThickness="0">
                        <FlowDocument>
                            <Paragraph>This is paragraph with border</Paragraph>
                        </FlowDocument>
                    </RichTextBox>                        
                </Border>
            </BlockUIContainer>    
        </FlowDocument>
    </RichTextBox>

答案 1 :(得分:0)

您可以通过以下方式完成:

<Border Height="315" Width="312" BorderBrush="Bisque"  VerticalAlignment="Top"  Margin="10,10,0,0" HorizontalAlignment="Left"   BorderThickness="2" CornerRadius="20">
        <RichTextBox x:Name="richTextBox"  Height="315"  VerticalAlignment="Bottom" BorderThickness="0"   Width="312" IsReadOnly="True" >

        </RichTextBox>
    </Border>
    <Border Height="315" Width="312" BorderBrush="Bisque"  VerticalAlignment="Top"  Margin="10,10,0,0" HorizontalAlignment="Left"   BorderThickness="2" CornerRadius="20" />

enter image description here