I have a simple WPF application with a button whose tooltip is binded to a TextBlock.Text:
<Grid>
<Button Height="23" Margin="82,0,120,105" Name="button1" VerticalAlignment="Bottom" ToolTip="{Binding ElementName=textBlock1,Path=Text}" Click="button1_Click">Button</Button>
<TextBlock Height="23" Margin="64,55,94,0" Name="textBlock1" VerticalAlignment="Top" Text="AD" />
</Grid>
In button1_Click, I have:
textBlock1.Text = null;
I expected no tooltip for the button after the button click. However, I am getting an emty tooltip. How do I fix this?
You cannot set the
Textto null, it will change to an empty string right away.Workaround #1: a style that clears the value:
Workaround #2: Add a
ValueConverterto the binding which returnsnullif thevalueisString.Empty.There might be other ways.