2016-08-13 20 views
0

我試圖創建文本框的提示,這是在我的應用程序中所有的TextBox我的風格代碼:如何在它的風格結合的文本框的工具提示標籤

enter image description here

我已經設置工具提示該文本框(1)

我想要的結合工具提示值的文本框(3)

現在,我只能讓「搜索...」的出現(2)

請幫助

更新代碼

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
       xmlns:local="clr-namespace:BTL.Themes"> 


<Style xmlns:sys="clr-namespace:System;assembly=mscorlib" 
     x:Key="TextField" 
     TargetType="{x:Type TextBox}"> 

    <Setter Property="VerticalContentAlignment" Value="Center" /> 
    <Setter Property="FontWeight" Value="Regular" /> 
    <Setter Property="Background" Value="Transparent" /> 
    <Setter Property="Foreground" Value="{DynamicResource BodyForeground1}" /> 
    <Setter Property="FontSize" Value="13" /> 
    <Setter Property="CaretBrush" Value="{DynamicResource BodyForeground1}" /> 
    <Setter Property="ToolTipService.InitialShowDelay" Value="250" /> 
    <Setter Property="Height" Value="24" /> 
    <Setter Property="BorderBrush" Value="{DynamicResource TextFieldNormalBorderBrush}" /> 
    <Setter Property="BorderThickness" Value="0 0 0 1" /> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type TextBox}"> 
       <ControlTemplate.Resources> 
        <VisualBrush x:Key="Hint" 
           AlignmentX="Left" 
           AlignmentY="Center" 
           Stretch="None"> 
         <VisualBrush.Visual> 
          <Label Content="Search..." Foreground="LightGray" /> 
         </VisualBrush.Visual> 
        </VisualBrush> 
       </ControlTemplate.Resources> 
       <Border Height="{TemplateBinding Height}" 
         Background="{TemplateBinding Background}" 
         BorderBrush="{TemplateBinding BorderBrush}" 
         BorderThickness="{TemplateBinding BorderThickness}" 
         SnapsToDevicePixels="True"> 
        <ScrollViewer x:Name="PART_ContentHost" 
            Height="{TemplateBinding Height}" 
            Margin="0 0 0 0" 
            VerticalAlignment="Bottom" 
            Focusable="false" 
            Foreground="{TemplateBinding Foreground}" 
            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" /> 
       </Border> 
       <ControlTemplate.Triggers> 
        <Trigger Property="IsEnabled" Value="False"> 
         <Setter Property="Opacity" Value="{DynamicResource DisabledOpacity}" /> 
         <Setter Property="BorderThickness" Value="0 0 0 0.5" /> 
        </Trigger> 
        <Trigger Property="IsFocused" Value="True"> 
         <!--<Setter Property="BorderThickness" Value="0 0 0 2" />--> 
         <Setter Property="BorderBrush" Value="{DynamicResource BodyFocusVisual}" /> 
        </Trigger> 
        <Trigger Property="Text" Value="{x:Static sys:String.Empty}"> 
         <Setter Property="Background" Value="{StaticResource Hint}" /> 
        </Trigger> 
       </ControlTemplate.Triggers> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 

+0

顯示您的源代碼,但不能作爲圖像... – ddb

+0

只需更新代碼,請大家看看 我想是這樣的: <標籤內容=「綁定工具提示」前景=「淺灰色」 /> (當然,它不工作) –

回答

0

只需使用TemplateBinding的標籤內容的文本框的工具提示和任何值分配給textboxName.ToolTip綁定將顯示爲標籤內容。

<VisualBrush.Visual> 
    <Label Content="{TemplateBinding ToolTip}" Foreground="LightGray" /> 
</VisualBrush.Visual> 
相關問題