2010-07-14 6 views
0

나는 이런 TextBox에 대한 Style이 : 그것은 편집 할 수 없습니다 때 회색 검은 색과 배경색으로 확인 전경색을 만들기 위해WPF 할당 된 배경이 스타일 트리거의 설정 값을 무시할 수없는 이유는 무엇입니까?

<Style x:Key="TextBox_Standard" TargetType="{x:Type TextBoxBase}" > 
    <Setter Property="Control.FontFamily" Value="/#Calibri" /> 
    <Setter Property="Control.FontSize" Value="12" /> 
    <Setter Property="Control.Margin" Value="2" /> 
    <Setter Property="Control.Height" Value="21" /> 
    <Setter Property="Control.VerticalAlignment" Value="Center" /> 
    <Setter Property="SnapsToDevicePixels" Value="True"/> 
    <Setter Property="UndoLimit" Value="0"/> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type TextBoxBase}"> 
      <Border 
       Name="Border" 
       CornerRadius="1" 
       Padding="1" 
       Background="{StaticResource WindowBackgroundBrush}" 
       BorderBrush="{StaticResource SolidBorderBrush}" 
       BorderThickness="1" > 
       <ScrollViewer Margin="0" x:Name="PART_ContentHost" /> 
      </Border> 
      <ControlTemplate.Triggers> 
       <Trigger Property="IsEnabled" Value="False"> 
        <Setter TargetName="Border" Property="Background" Value="{StaticResource DisabledBackgroundBrush}"/> 
        <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/> 
        <Setter Property="Cursor" Value="Arrow"/> 
       </Trigger> 
       <Trigger Property="IsReadOnly" Value="True"> 
        <Setter TargetName="Border" Property="Background" Value="{StaticResource DisabledBackgroundBrush}"/> 
        <Setter Property="Focusable" Value="False"/> 
        <Setter Property="Cursor" Value="Arrow"/> 
       </Trigger> 
      </ControlTemplate.Triggers> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

을 하였다.

하지만 분명히 지금 거기가 편집 할 수 없습니다 때 프로그래밍 배경을 변경하기위한 요구 사항, 그래서 이런 식으로 그것을 시도 :

txtBox.Background = Brushes.Yellow;

을하지만 발생하는 것은 여전히 ​​흰색 배경을 가지고 있습니다 편집과 회색 편집 할 수없는 경우 배경.

어디서 잘못 되었나요? 나는 새로운 스타일을 만들어, 난 그냥 싶어하여 한 :

답변

0

단지 불행하게도 내가 실제로하지 않을 때 편집 참고 노란색으로해야, 내가 그것을 편집 모드에서 때이 작동하고 볼이

<Style x:Key="TextBox_Standard" TargetType="{x:Type TextBoxBase}" > 
     <Setter Property="Control.FontFamily" Value="/#Calibri" /> 
     <Setter Property="Control.FontSize" Value="12" /> 
     <Setter Property="Control.Margin" Value="2" /> 
     <Setter Property="Control.Height" Value="21" /> 
     <Setter Property="Control.VerticalAlignment" Value="Center" /> 
     <Setter Property="SnapsToDevicePixels" Value="True"/> 
     <Setter Property="Background" Value="{StaticResource WindowBackgroundBrush}"></Setter> 
     <Setter Property="UndoLimit" Value="0"/> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type TextBoxBase}"> 
        <Border 
      Name="Border" 
      CornerRadius="1" 
      Padding="1" 
      Background="{TemplateBinding Background}" 
      BorderBrush="{StaticResource SolidBorderBrush}" 
      BorderThickness="1" > 
         <ScrollViewer Margin="0" x:Name="PART_ContentHost" /> 
        </Border> 
        <ControlTemplate.Triggers> 

         <Trigger Property="IsEnabled" Value="False"> 
          <Setter TargetName="Border" Property="Background" Value="{StaticResource DisabledBackgroundBrush}"/> 
          <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/> 
          <Setter Property="Cursor" Value="Arrow"/> 
         </Trigger> 
         <Trigger Property="IsReadOnly" Value="True"> 
          <Setter TargetName="Border" Property="Background" Value="{StaticResource DisabledBackgroundBrush}"/> 
          <Setter Property="Focusable" Value="False"/> 
          <Setter Property="Cursor" Value="Arrow"/> 
         </Trigger> 
        </ControlTemplate.Triggers> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 
+0

으로 시도 두 가지 경우 모두 사용할 수 있도록 현재 스타일을 수정하여 할 수 있는지 확인하십시오. (1) 텍스트 상자 A -> 편집 가능 - 흰색, 편집 불가능 - 회색, (2) 텍스트 상자 B -> 편집 가능 - 프로그래밍 방식 , 편집 불가능 - 프로그래밍 방식으로 – dnr3

+0

아니요, 두 가지 경우에서 동일한 스타일을 사용할 수 없습니다. 트리거를 사용할 때마다 IsReadonly 또는 Is가 실행될 때마다 실행됩니다. Enabled 속성 값이 변경되었습니다. 트리거없이 A에서 사용할 스타일을 B에서 사용하도록 새 스타일을 만들 수 있습니다. – akjoshi

+0

아, 그러니 어쩔 수 없어요. T_T 글쎄, 그냥 새 스타일을 만들거야. 고마워. – dnr3

관련 문제