2016-04-25 17 views
0

TextBoxがReadOnlyのときにScrollViewerが有効になっていないという問題があります。TextBox ScrollviewerがReadOnlyで機能していない 'True'

<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は読み取り専用である後に誰もがScrollViewerのが有効にする方法を知っていますか?

+0

でテンプレートを取得? – Pikoh

+0

いつもReadOnlyというわけではないからです。 通知があり、通知を終了した後はテキストを追加するだけで既存のテキストを変更することはできません –

答えて

0

問題を再現しようとしていますが、垂直スクロールバーは常に有効です。ここでコードを使用しています。あなたの代わりに `TextBlock`を使用していない理由、それは、読み取り専用になりたい場合は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をブロックする別のコントロールがありました。 –

関連する問題