tags:

views:

80

answers:

1
<Style TargetType="{x:Type TextBox}">
    <Setter Property="Margin" Value="1"></Setter>
    <Setter Property="Background" Value="{x:Null}"/>
    <Setter Property="BorderThickness" Value="0"/>
    <Setter Property="ToolTip">
        <Setter.Value>
            <DockPanel Background="Gray">
                <TextBlock Text="{Binding Source={ TextBox.Text}}"/>
            </DockPanel>
        </Setter.Value>
    </Setter>
    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="Background" Value="Wheat"></Setter>
        </Trigger>
    </Style.Triggers>


</Style>

========================================

"<TextBlock Text="{Binding Source={ TextBox.Text}}"/>"

I want to bind the textbox text to the Textbox's property such as text or something. but you know what I think above dose't work. can you help me ,thank you very much

A: 

Try this Code:

<Style TargetType="ToolTip">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="ToolTip">
        <DockPanel Background="Gray">
          <ContentPresenter/>
        </DockPanel>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

<Style TargetType="{x:Type TextBox}">
  <Setter Property="Margin" Value="1"/>
  <Setter Property="Background" Value="{x:Null}"/>
  <Setter Property="BorderThickness" Value="0"/>
  <Setter Property="ToolTip" Value="{Binding Text, RelativeSource={RelativeSource self}}"/>
  <Style.Triggers>
    <Trigger Property="IsMouseOver" Value="True">
      <Setter Property="Background" Value="Wheat"/>
    </Trigger>
  </Style.Triggers>
</Style>
rantri
thankyou very much.it's work ,but I am trying to add more info in the tootipso I add ablow codes but it's doesn't work angain.the msdn is difficult to understand <Setter.Value> <DockPanel Background="Gray"> <TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType=TextBox,AncestorLevel=2,Mode=FindAncestor},Path=Text}"/> </DockPanel> </Setter.Value>
jciwolf