2014-10-28 110 views
1

在我的Windows手機應用程序,我有我的文本框的邊框設置爲空: 如何改變TextBox邊框的顏色,當它有焦點?

但是,當它具有焦點,它仍然顯示出偏藍的顏色作爲其邊框。我如何配置這種顏色? 我試圖尋找在模板的文本框,我看不出有對色彩邊界,當它具有焦點屬性:

有沒有人有任何想法,如果這是多變的?

<Thickness x:Key="TextControlHeaderMarginThemeThickness">0,0,0,4.8</Thickness> 
    <x:Double x:Key="TextControlThemeMinHeight">33</x:Double> 
    <x:Double x:Key="ContentControlFontSize">20.26</x:Double> 
    <SolidColorBrush x:Key="TextBoxDisabledBackgroundThemeBrush" Color="Transparent" /> 
    <x:Double x:Key="TextControlBackgroundThemeOpacity">0.8</x:Double> 
    <x:Double x:Key="TextControlBorderThemeOpacity">0.8</x:Double> 
    <ControlTemplate x:Key="TextBoxControlTemplate1" TargetType="TextBox"> 
     <Grid> 
      <VisualStateManager.VisualStateGroups> 
       <VisualStateGroup x:Name="CommonStates"> 
        <VisualState x:Name="Disabled"> 
         <Storyboard> 
          <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundElement" Storyboard.TargetProperty="Background"> 
           <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxDisabledBackgroundThemeBrush}" /> 
          </ObjectAnimationUsingKeyFrames> 
          <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" Storyboard.TargetProperty="BorderBrush"> 
           <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxDisabledBorderThemeBrush}" /> 
          </ObjectAnimationUsingKeyFrames> 
          <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentElement" Storyboard.TargetProperty="Foreground"> 
           <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxDisabledForegroundThemeBrush}" /> 
          </ObjectAnimationUsingKeyFrames> 
          <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PlaceholderTextContentPresenter" Storyboard.TargetProperty="Foreground"> 
           <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxDisabledForegroundThemeBrush}" /> 
          </ObjectAnimationUsingKeyFrames> 
         </Storyboard> 
        </VisualState> 
        <VisualState x:Name="Normal"> 
         <Storyboard> 
          <DoubleAnimation Storyboard.TargetName="BackgroundElement" Storyboard.TargetProperty="Opacity" Duration="0" 
           To="{ThemeResource TextControlBackgroundThemeOpacity}" /> 
          <DoubleAnimation Storyboard.TargetName="BorderElement" Storyboard.TargetProperty="Opacity" Duration="0" 
           To="{ThemeResource TextControlBorderThemeOpacity}" /> 
         </Storyboard> 
        </VisualState> 
        <VisualState x:Name="Focused"> 
         <Storyboard> 
          <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" Storyboard.TargetProperty="BorderBrush"> 
           <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextSelectionHighlightColorThemeBrush}" /> 
          </ObjectAnimationUsingKeyFrames> 
          <DoubleAnimation Storyboard.TargetName="PlaceholderTextContentPresenter" Storyboard.TargetProperty="Opacity" Duration="0" To="0" /> 
          <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BackgroundElement" Storyboard.TargetProperty="Background"> 
           <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextBoxFocusedBackgroundThemeBrush}" /> 
          </ObjectAnimationUsingKeyFrames> 
         </Storyboard> 
        </VisualState> 
       </VisualStateGroup> 
      </VisualStateManager.VisualStateGroups> 
      <Grid.RowDefinitions> 
       <RowDefinition Height="Auto"/> 
       <RowDefinition Height="*"/> 
      </Grid.RowDefinitions> 
      <Border x:Name="BackgroundElement" Grid.Row="1" Background="{TemplateBinding Background}" Margin="{TemplateBinding BorderThickness}" /> 
      <Border x:Name="BorderElement" Grid.Row="1" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" /> 
      <ContentPresenter x:Name="HeaderContentPresenter" Grid.Row="0" Style="{StaticResource HeaderContentPresenterStyle}" Margin="{ThemeResource TextControlHeaderMarginThemeThickness}" 
       Content="{TemplateBinding Header}" ContentTemplate="{TemplateBinding HeaderTemplate}" /> 
      <ScrollViewer x:Name="ContentElement" Grid.Row="1" MinHeight="{ThemeResource TextControlThemeMinHeight}" 
       HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}" 
       HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}" 
       VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}" 
       VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}" 
       IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}" 
       IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}" 
       IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}" Margin="{TemplateBinding BorderThickness}" 
       Padding="{TemplateBinding Padding}" IsTabStop="False" ZoomMode="Disabled" 
       AutomationProperties.AccessibilityView="Raw"/> 
      <ContentControl x:Name="PlaceholderTextContentPresenter" Grid.Row="1" Foreground="{ThemeResource TextBoxPlaceholderTextThemeBrush}" 
       FontSize="{ThemeResource ContentControlFontSize}" Margin="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}" 
       IsTabStop="False" Content="{TemplateBinding PlaceholderText}" /> 
     </Grid> 
    </ControlTemplate> 

回答

1

突出顯示是通過StoryBoard動畫完成的。

特別是這一個在您的Style

<VisualState x:Name="Focused"> 
    <Storyboard> 
     <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" Storyboard.TargetProperty="BorderBrush"> 
      <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource TextSelectionHighlightColorThemeBrush}" /> 
     </ObjectAnimationUsingKeyFrames> 
     <!--- .... ---> 
    </Storyboard> 
</VisualState> 

您可以擺脫它(刪除它),或改變價值觀說紅

<VisualState x:Name="Focused"> 
    <Storyboard> 
     <ObjectAnimationUsingKeyFrames Storyboard.TargetName="BorderElement" Storyboard.TargetProperty="BorderBrush"> 
      <DiscreteObjectKeyFrame KeyTime="0" Value="Red" /> 
     </ObjectAnimationUsingKeyFrames> 
     <!--- .... ---> 
    </Storyboard> 
</VisualState> 

enter image description here


如果你擺脫了專注於StoryBoard動畫,那麼你可以設置通過改變BorderElement BorderBrush的顏色

<Border x:Name="BorderElement" BorderBrush="Red" BorderThickness="{TemplateBinding BorderThickness}" Grid.Row="1"/> 
+0

如何在TextBox具有焦點時更改「藍色圓圈」的顏色。我改變了'TextSelectionHighlightColorThemeBrush',但那不是。 – n179911 2014-10-28 17:47:46

+0

@ n179911我認爲它與手機上的PhoneAccentBrush設置綁定。如果它是可改變的(我認爲它不是這樣),你可以通過改變主題來做到這一點。這裏是一個有用的鏈接:http://stackoverflow.com/questions/11095980/how-to-override-the-phoneaccentbrush-in-windowsphone – 2014-10-29 04:50:56

+0

@ n179911需要糾正自己在這裏,你可以重寫PhoneAccentBrush,有人甚至編譯了代碼進入圖書館http://www.jeff.wilcox.name/2012/01/phonethememanager/ – 2014-11-07 00:14:26

相關問題