Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wpf textbox tootip binding itself value

Tags:

binding

wpf

<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

like image 624
jciwolf Avatar asked Apr 15 '10 09:04

jciwolf


2 Answers

Here is the answer

<TextBox Text="Now is the winter of our discontent Made glorious summer by this sun of York; And all the clouds that lour'd upon our house In the deep bosom of the ocean buried."
    ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Text}"
    Width="100" Margin="10"/>

It was found at https://wpf.2000things.com/2011/08/29/374-using-a-tooltip-to-display-the-full-contents-of-a-textbox/

like image 108
Friend Avatar answered Oct 20 '22 01:10

Friend


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>
like image 44
rantri Avatar answered Oct 20 '22 00:10

rantri