2012-03-02 66 views
2

我正在爲PhoneTextBox重寫樣式,將默認背景更改爲「transpanrent」,將前景更改爲「White」,將BorderBrush更改爲「White」,因爲我想設計一個黑暗的主題。在windows phone中定義PhoneTextBox的樣式

但是問題出現了,文本輸入指示器消失了。我感謝原因是文本輸入指示器的前景是黑色的,所以用戶看不到它。但是我找不到一種方法來定義文本輸入指示符的前景。任何提示將被appricated。

PS。我不知道如何描述這個指標,所以我編了一個單詞「text-input-indicator」,如下圖所示:

正常情況下,黑色豎線顯示出來。

enter image description here

重寫樣式後,用戶不能看到黑色垂直線:

enter image description here

和XAML代碼:

<Style x:Key="PhoneTextBoxStyle" TargetType="toolkit:PhoneTextBox"> 
     <Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilyNormal}"/> 
     <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMediumLarge}"/> 
     <Setter Property="Background" Value="Transparent"/> 
     <Setter Property="Foreground" Value="White"/> 
     <Setter Property="BorderBrush" Value="White"/> 
     <Setter Property="SelectionBackground" Value="{StaticResource PhoneAccentBrush}"/> 
     <Setter Property="SelectionForeground" Value="White"/> 
     <Setter Property="BorderThickness" Value="2"/> 
     <Setter Property="Padding" Value="{StaticResource PhoneBorderThickness}"/> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="toolkit:PhoneTextBox"> 
        <Grid x:Name="RootGrid" Background="Transparent"> 
         <VisualStateManager.VisualStateGroups> 
          <VisualStateGroup x:Name="CommonStates"> 
           <VisualState x:Name="Disabled"> 
           </VisualState> 
           <VisualState x:Name="Enabled"> 
           </VisualState> 
          </VisualStateGroup> 
          <VisualStateGroup x:Name="FocusStates"> 
           <VisualState x:Name="Focused"> 
           </VisualState> 
           <VisualState x:Name="Unfocused"/> 
          </VisualStateGroup> 
          <VisualStateGroup x:Name="LengthIndicatorStates"> 
           <VisualState x:Name="LengthIndicatorVisible"> 
            <Storyboard> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="LengthIndicator"> 
              <DiscreteObjectKeyFrame KeyTime="0:0:0"> 
               <DiscreteObjectKeyFrame.Value> 
                <Visibility>Visible</Visibility> 
               </DiscreteObjectKeyFrame.Value> 
              </DiscreteObjectKeyFrame> 
             </ObjectAnimationUsingKeyFrames> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Margin" Storyboard.TargetName="RootGrid"> 
              <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="0, 0, 0, 27"/> 
             </ObjectAnimationUsingKeyFrames> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="LengthIndicator"> 
              <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="0.6"/> 
             </ObjectAnimationUsingKeyFrames> 
             <DoubleAnimation Duration="0:0:0.350" To="32" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.Y)" Storyboard.TargetName="LengthIndicator"> 
              <DoubleAnimation.EasingFunction> 
               <ExponentialEase Exponent="6"/> 
              </DoubleAnimation.EasingFunction> 
             </DoubleAnimation> 
            </Storyboard> 
           </VisualState> 
           <VisualState x:Name="LengthIndicatorHidden"> 
            <Storyboard> 
             <DoubleAnimation Duration="0:0:0.350" To="0" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.Y)" Storyboard.TargetName="LengthIndicator"> 
              <DoubleAnimation.EasingFunction> 
               <ExponentialEase Exponent="6"/> 
              </DoubleAnimation.EasingFunction> 
             </DoubleAnimation> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Margin" Storyboard.TargetName="RootGrid"> 
              <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="0, 0, 0, 0"/> 
             </ObjectAnimationUsingKeyFrames> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="LengthIndicator"> 
              <DiscreteObjectKeyFrame KeyTime="0:0:0.350" Value="0"/> 
             </ObjectAnimationUsingKeyFrames> 
             <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="LengthIndicator"> 
              <DiscreteObjectKeyFrame KeyTime="0:0:0.350"> 
               <DiscreteObjectKeyFrame.Value> 
                <Visibility>Collapsed</Visibility> 
               </DiscreteObjectKeyFrame.Value> 
              </DiscreteObjectKeyFrame> 
             </ObjectAnimationUsingKeyFrames> 
            </Storyboard> 
           </VisualState> 
          </VisualStateGroup> 
         </VisualStateManager.VisualStateGroups> 
         <Border x:Name="LengthIndicatorBorder"> 
          <TextBlock x:Name="LengthIndicator" Foreground="{StaticResource PhoneContrastBackgroundBrush}" FontSize="{StaticResource PhoneFontSizeNormal}" HorizontalAlignment="Right" Margin="0" Opacity="0" TextAlignment="Right" VerticalAlignment="Bottom"> 
            <TextBlock.RenderTransform> 
             <TranslateTransform/> 
            </TextBlock.RenderTransform> 
          </TextBlock> 
         </Border> 
         <Border x:Name="HintBorder" BorderBrush="{TemplateBinding BorderBrush}" 
           BorderThickness="{TemplateBinding BorderThickness}" 
           Background="{TemplateBinding Background}" Margin="0"> 
          <Grid> 
           <ContentControl x:Name="HintContent" Background="Transparent" Content="{TemplateBinding Hint}" 
               HorizontalAlignment="Left" Margin="3,5,3,0" Style="{TemplateBinding HintStyle}" 
               Foreground="Gray" 
               Visibility="{TemplateBinding ActualHintVisibility}" VerticalAlignment="Top"/> 
           <ContentControl x:Name="ContentElement" BorderThickness="0" HorizontalContentAlignment="Stretch" 
               Margin="{StaticResource PhoneTextBoxInnerMargin}" 
               Padding="{TemplateBinding Padding}" 
               VerticalContentAlignment="Stretch"/> 
          </Grid> 
         </Border> 
         <Border x:Name="TextBorder" BorderBrush="White" 
           BorderThickness="{TemplateBinding BorderThickness}" 
           Background="Transparent" Margin="0" Visibility="Collapsed"> 
          <TextBox x:Name="Text" Foreground="White" 
            FontWeight="{TemplateBinding FontWeight}" FontStyle="{TemplateBinding FontStyle}" 
            FontSize="{TemplateBinding FontSize}" FontFamily="{TemplateBinding FontFamily}" 
            HorizontalAlignment="Left" SelectionForeground="{TemplateBinding SelectionForeground}" 
            SelectionBackground="{TemplateBinding SelectionBackground}" 
            TextAlignment="{TemplateBinding TextAlignment}" TextWrapping="{TemplateBinding TextWrapping}" 
            Text="{TemplateBinding Text}"/> 
         </Border> 
         <Border x:Name="ActionIconBorder" Background="Transparent" HorizontalAlignment="Right" Height="54" VerticalAlignment="Bottom" Width="54"> 
          <Image x:Name="ActionIcon" Height="54" Source="{TemplateBinding ActionIcon}" Width="54"/> 
         </Border> 
         <TextBlock x:Name="MeasurementTextBlock" FontWeight="{TemplateBinding FontWeight}" FontStyle="{TemplateBinding FontStyle}" FontStretch="{TemplateBinding FontStretch}" FontSize="{TemplateBinding FontSize}" FontFamily="{TemplateBinding FontFamily}" IsHitTestVisible="False" Margin="8" Opacity="0" TextAlignment="{TemplateBinding TextAlignment}" TextWrapping="{TemplateBinding TextWrapping}" Text="{TemplateBinding Text}"/> 
        </Grid> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 

回答

0

也許你找CaretBrushSelectionBackgroundSelectionForeground。我不知道這些屬性是否綁定或不在toolkit:PhoneTextBox中,但是您絕對可以在任何情況下手動重新設置它。

+0

好的,謝謝,@ Ku6opr。我只需要重新設置caretBrush。 – ellic 2012-03-02 13:39:43

+0

很高興幫助。在文本選擇過程中檢查顏色,以在黑暗和白色的主題都做到這一點,也 – Ku6opr 2012-03-02 13:48:20

0

如果有人正在尋找解決方案,改變lengthIndicator性質

<Border x:Name="LengthIndicatorBorder"> 
    <TextBlock x:Name="LengthIndicator" HorizontalAlignment="Right" Margin="0" Opacity="0" TextAlignment="Right" VerticalAlignment="Bottom"> 
      <TextBlock.RenderTransform> 
       <TranslateTransform/> 
      </TextBlock.RenderTransform> 
    </TextBlock> 
</Border> 

此塊就是你需要

+0

謝謝,Sorokin。 – ellic 2012-11-01 02:59:26