2013-10-17 14 views
1

我正在使用以下TextBox樣式。如果我繼續在文本框中輸入內容,如果文本變得太長,它將不會滾動到插入位置。而且我也無法拖動滾動文字。我錯過了什麼嗎?當文本太長時,自定義模板化TextBox不會滾動到新字符

<Style x:Key="TextBoxStyle" TargetType="{x:Type TextBox}"> 
    <Setter Property="Foreground" Value="White"/> 
    <Setter Property="Background" Value="{StaticResource TextBoxBackgroundBrush}"/> 
    <Setter Property="BorderBrush" Value="{StaticResource TextBoxBorderBrush}"/> 
    <Setter Property="BorderThickness" Value="2"/> 
    <Setter Property="FontSize" Value="26"/> 
    <Setter Property="TextWrapping" Value="Wrap"/> 
    <Setter Property="MaxLines" Value="1"/> 
    <Setter Property="Padding" Value="5"/> 
    <Setter Property="SnapsToDevicePixels" Value="True"/> 
    <Setter Property="Height" Value="50"/> 
    <Setter Property="FocusVisualStyle" Value="{x:Null}"/> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type TextBox}"> 
       <Grid> 
        <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" 
        Background="{TemplateBinding Background}" CornerRadius="2" SnapsToDevicePixels="true"> 
         <Border.Effect> 
          <DropShadowEffect Direction="-90" ShadowDepth="2"/> 
         </Border.Effect> 
        </Border> 
        <Border BorderBrush="{TemplateBinding BorderBrush}" x:Name="GlowBd" BorderThickness="2" CornerRadius="2" SnapsToDevicePixels="true"> 
         <Border.Effect> 
          <DropShadowEffect Direction="360" BlurRadius="6" ShadowDepth="0"/> 
         </Border.Effect> 
        </Border> 
        <Grid Margin="2"> 
         <Grid.ColumnDefinitions> 
          <ColumnDefinition Width="auto"/> 
          <ColumnDefinition Width="*"/> 
         </Grid.ColumnDefinitions> 
         <ContentControl Content="{TemplateBinding Tag}"/> 
         <ScrollViewer Grid.Column="1" Margin="{TemplateBinding Padding}" x:Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> 
        </Grid> 
       </Grid> 
       <!-- Some triggers --> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 
+0

你能到達終點其他方式的字符串(滾動條,滾輪等)? – XAMeLi

回答

0

此位:<Setter Property="TextWrapping" Value="Wrap"/>說:讓這個文本框滾動到下一行,當你到達它。

這位:<Setter Property="MaxLines" Value="1"/>說:我想要它最多有1行。

刪除第一個,會導致新的文本將舊的文本推向左邊(您可以通過點擊左鍵達到足夠的時間)。

刪除第二個,將導致新的文本推動舊的(你可以通過點擊向上鍵達到它)。

你想達到什麼目的?

0

的ScrollViewer中的這種情況下的內容是文本,所以如果你想要的文字引起滾動,設置在ScrollViewer中的CanContentScroll財產...

<ScrollViewer Grid.Column="1" Margin="{TemplateBinding Padding}" x:Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" CanContentScroll="True" /> 
相關問題