2009-12-09 6 views
3

Il est possible de faire RichTextBox avoir un rayon de coin en wpf. Je sais qu'il peut être utilisé avec ControlTemplate mais comment?Coin arrondi de RichTextBox dans wpf

J'espère que certains d'entre vous me donneront un indice.

Répondre

4

Que diriez-vous de mettre une bordure autour d'elle?

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

si le développeur de richtextbox n'a pas de rayon de coin frontière développé, vous devez le faire yourselfe. Je suis d'accord avec Klaus. – Nasenbaer

2

J'ai essayé la suggestion de Klau, et cela n'a pas fonctionné pour moi, alors je suis venu avec un peu de quelque chose sur moi-même:

<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> 

Je l'ai remplacé par défaut du RichTextBoxe frontière avec la classe des frontières, et cette fois-ci cela fonctionne:

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

et l'image:

RichTextBox with rounded corners

Vous pouvez probablement faire cela mieux, mais c'est un bon début