2009-12-09 99 views
3

Rich Rich Rich Rich Rich Rich Rich Rich Rich Rich Rich Rich Rich Rich我知道它可以使用ControlTemplate存档,但是如何?wpf中RichTextBox的圆角012

我希望你们中的一些人可以提供给我一个提示。

回答

4

如何在它周围放置边框?

<Border BorderThickness="2" CornerRadius="6"> 
<your:RichTextBox /> 
</Border> 
+2

如果RichTextBox的开发商没有边框圆角半径开发的,你需要做的是yourselfe。我同意克劳斯。 – Nasenbaer 2011-12-21 07:42:33

2

我已经试过·克劳的建议,并没有为我工作,所以我的东西一点点来对我自己:

<Window.Resources> 
    <LinearGradientBrush x:Key="TextBoxBorder" EndPoint="0,20" MappingMode="Absolute" StartPoint="0,0"> 
     <GradientStop Color="#ABADB3" Offset="0.05"/> 
     <GradientStop Color="#E2E3EA" Offset="0.07"/> 
     <GradientStop Color="#E3E9EF" Offset="1"/> 
    </LinearGradientBrush> 
    <Style x:Key="{x:Type TextBoxBase}" BasedOn="{x:Null}" TargetType="{x:Type TextBoxBase}"> 
     <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> 
     <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/> 
     <Setter Property="BorderBrush" Value="{StaticResource TextBoxBorder}"/> 
     <Setter Property="BorderThickness" Value="1"/> 
     <Setter Property="Padding" Value="1"/> 
     <Setter Property="AllowDrop" Value="true"/> 
     <Setter Property="FocusVisualStyle" Value="{x:Null}"/> 
     <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/> 
     <Setter Property="Stylus.IsFlicksEnabled" Value="False"/> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type TextBoxBase}"> 
        <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true" CornerRadius="20" BorderThickness="9,6,10,7"> 
         <ScrollViewer x:Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> 
        </Border> 
        <ControlTemplate.Triggers> 
         <Trigger Property="IsEnabled" Value="false"> 
          <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/> 
          <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> 
         </Trigger> 
        </ControlTemplate.Triggers> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 
    <Style x:Key="{x:Type Hyperlink}" TargetType="{x:Type Hyperlink}"> 
     <Setter Property="Foreground" Value="Blue"/> 
     <Setter Property="TextDecorations" Value="Underline"/> 
     <Style.Triggers> 
      <Trigger Property="IsMouseOver" Value="true"> 
       <Setter Property="Foreground" Value="Red"/> 
      </Trigger> 
      <Trigger Property="IsEnabled" Value="false"> 
       <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> 
      </Trigger> 
      <Trigger Property="IsEnabled" Value="true"> 
       <Setter Property="Cursor" Value="Hand"/> 
      </Trigger> 
     </Style.Triggers> 
    </Style> 
    <Style x:Key="RichTextBoxWithRoundedCorners" TargetType="{x:Type RichTextBox}"> 
     <Style.Resources> 
      <Style x:Key="{x:Type FlowDocument}" TargetType="{x:Type FlowDocument}"> 
       <Setter Property="OverridesDefaultStyle" Value="true"/> 
      </Style> 
      <Style x:Key="{x:Type Hyperlink}" BasedOn="{StaticResource {x:Type Hyperlink}}" TargetType="{x:Type Hyperlink}"> 
       <Style.Triggers> 
        <Trigger Property="IsMouseOver" Value="true"> 
         <Setter Property="Foreground" Value="Blue"/> 
        </Trigger> 
        <Trigger Property="IsEnabled" Value="false"> 
         <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> 
        </Trigger> 
       </Style.Triggers> 
      </Style> 
     </Style.Resources> 
     <Setter Property="MinWidth" Value="10"/> 
     <Style.BasedOn> 
      <StaticResource ResourceKey="{x:Type TextBoxBase}"/> 
     </Style.BasedOn> 
    </Style> 
</Window.Resources> 

我已经取代了RichTextBoxe的默认与边框类的边框,这一次,它的工作原理:

<RichTextBox Background="White" Margin="75,0,114,94" Height="125" VerticalAlignment="Bottom" Style="{StaticResource RichTextBoxWithRoundedCorners}" /> 

而且图片:

RichTextBox with rounded corners

你也许可以让这个更好的,但是这是一个良好的开端