<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}}"/>"
我想将文本框文本绑定到Textbox的属性,例如文本或其他内容。 但是你知道我认为上面的东西不起作用。 你能帮助我吗,非常感谢你
答案 0 :(得分:20)
以下是答案
<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"/>
发现于https://wpf.2000things.com/2011/08/29/374-using-a-tooltip-to-display-the-full-contents-of-a-textbox/
答案 1 :(得分:2)
试用此代码:
<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>