开发者

wpf textbox tootip binding itself value

<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>
开发者_如何学Python            <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


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/


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜