2016-04-25 23 views
0

我有問題,當TextBox是ReadOnly ScrollViewer未啓用。TextBox滾動查看器不工作ReadOnly'真'

<TextBox x:Name="txtOmschrijving" IsEnabled="True" Grid.Column="1"HorizontalAlignment="Stretch" Text="{Binding Notification.DescLC}" TextWrapping="Wrap" MaxLength="2500" AcceptsReturn="True" Grid.RowSpan="2"Grid.ColumnSpan="2"ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollBarVisibility="Visible"TextChanged="TextChanged" LostFocus="txt_LostFocus"/> 

有沒有人知道如何使TextBox是ReadOnly後scrollviewer啓用?

+0

模板如果你希望它是隻讀的,爲什麼不使用'TextBlock'呢? – Pikoh

+0

因爲它不總是隻讀。 我們有通知,關閉通知後只能添加文本而不能修改現有文本 –

回答

0

我一直在試圖重現問題沒有成功,垂直滾動條總是啓用。這裏是我使用的代碼。獲得了Expression Blend的

<Window 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:local="clr-namespace:WpfApplication1" 
    xmlns:Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" x:Class="WpfApplication1.MainWindow" 
    mc:Ignorable="d" 
    Title="MainWindow" Height="350" Width="525"> 
<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="TextBoxStyle1" BasedOn="{x:Null}" TargetType="{x:Type TextBox}"> 
     <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 TextBox}"> 
        <Themes:ListBoxChrome x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderFocused="{TemplateBinding IsKeyboardFocusWithin}" SnapsToDevicePixels="true"> 
         <ScrollViewer x:Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> 
        </Themes:ListBoxChrome> 
        <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.Triggers> 
      <MultiTrigger> 
       <MultiTrigger.Conditions> 
        <Condition Property="IsInactiveSelectionHighlightEnabled" Value="true"/> 
        <Condition Property="IsSelectionActive" Value="false"/> 
       </MultiTrigger.Conditions> 
       <Setter Property="SelectionBrush" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightBrushKey}}"/> 
      </MultiTrigger> 
     </Style.Triggers> 
    </Style> 
</Window.Resources> 
<TextBox x:Name="textBox" 
     HorizontalAlignment="Left" 
     MaxLength="2500" 
     AcceptsReturn="True" 
     ScrollViewer.HorizontalScrollBarVisibility="Visible" 
     IsReadOnly="True" 
     Text="what is your name, my name is john do" Height="23" IsEnabled="True" ScrollViewer.VerticalScrollBarVisibility="Visible" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Style="{DynamicResource TextBoxStyle1}"> 
</TextBox> 

+0

感謝您的回答。 發現這個問題,現在它的工作。 還有另一個控件阻止ScrollViewer。 –