2014-03-29 5 views
1

눌렀을 때 텍스트 블록 텍스트의 전경을 변경하기 위해 http://msdn.microsoft.com/en-us/library/cc645061(v=vs.95).aspx을 참조하고 있었지만 <Setter Property="Template">The member 'Template' is not recognized or is not accessible이라는 오류가 표시됩니다. 기본적으로 전경을 장치의 PhoneAccentBrush으로 설정하고 누른 다음 전경을 PhoneDisabledBrush (칙칙한 색)으로 설정합니다. WP8에서 어떻게이 작업을 수행 할 수 있습니까?누르면 TextBlock 전경 변경

<Style x:Key="TextBlockStyle1" TargetType="TextBlock"> 
     <Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilyNormal}"/> 
     <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeNormal}"/> 
     <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/> 
     <Setter Property="Margin" Value="{StaticResource PhoneHorizontalMargin}"/> 
     <Setter Property="Template"> <!-- Error: The member 'Template' is not recognized or is not accessible. --> 
      <Setter.Value> 
       <ControlTemplate TargetType="TextBox"> 
        <Grid x:Name="RootElement"> 
         <vsm:VisualStateManager.VisualStateGroups> 
          <vsm:VisualStateGroup x:Name="CommonStates"> 
           <vsm:VisualState x:Name="Normal"/> 
           <vsm:VisualState x:Name="MouseOver"> 
            <Storyboard> 
             <ColorAnimation Storyboard.TargetName="MouseOverBorder" Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)" To="#FF99C1E2" Duration="0"/> 
            </Storyboard> 
           </vsm:VisualState> 
           <vsm:VisualState x:Name="Disabled"> 
            <Storyboard> 
             <DoubleAnimation Storyboard.TargetName="DisabledVisualElement" Storyboard.TargetProperty="Opacity" To="1" Duration="0"/> 
            </Storyboard> 
           </vsm:VisualState> 
          </vsm:VisualStateGroup> 
         </vsm:VisualStateManager.VisualStateGroups> 
        </Grid> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 

    </Style> 

답변

1

TextBlock에는 Template 속성이 없습니다. 주위를 둘러싼 작업으로 Button을 만들어 TextBlock으로 사용자 정의 할 수 있습니다.

 <Button Content="Test" 
       Foreground="{StaticResource PhoneAccentBrush}"> 
      <Button.Style> 
       <Style TargetType="Button"> 
        <Setter Property="Template"> 
         <Setter.Value> 
          <ControlTemplate TargetType="Button"> 
           <Grid Background="Transparent"> 
            <VisualStateManager.VisualStateGroups> 
             <VisualStateGroup x:Name="CommonStates"> 
              <VisualState x:Name="Pressed"> 
               <Storyboard> 
                <ObjectAnimationUsingKeyFrames 
                 Storyboard.TargetProperty="Foreground" 
                 Storyboard.TargetName="Txt"> 
                 <DiscreteObjectKeyFrame KeyTime="0" 
                       Value="{StaticResource PhoneDisabledBrush}" /> 
                </ObjectAnimationUsingKeyFrames> 
               </Storyboard> 
              </VisualState> 
             </VisualStateGroup> 
            </VisualStateManager.VisualStateGroups> 

            <TextBlock x:Name="Txt" 
               Foreground="{TemplateBinding Foreground}" 
               Text="{TemplateBinding Content}" /> 

           </Grid> 
          </ControlTemplate> 
         </Setter.Value> 
        </Setter> 
       </Style> 
      </Button.Style> 
     </Button> 
: 여기

은 일례이며