Page 1 of 1

Can't get Tooltip to update

Posted: 29 Dec 2019, 10:01
by Jamieh
So I have a ToolTip on a Border. I've tried it several ways in XAML to make this work--this is the simplest:
<Border.ToolTip>
  <Border BorderBrush="Black" BorderThickness="0" Background="OldLace">
    <TextBlock Text="{Binding ToolTipText}" Foreground="Black" Padding="5" FontSize="18" />
  </Border>
</Border.ToolTip>
I have INotifyPropertyChanged implemented on the ViewModel and OnPropertyChanged is firing for ToolTipText. But the ToolTip will just not update. It sticks with whatever is the value the first time it is opened.

Any ideas as to what I'm doing wrong or how I can get my ToolTip to update on a data change?

Thanks.

Re: Can't get Tooltip to update

Posted: 30 Dec 2019, 10:00
by sfernandez
Which version of Noesis are you using, because the test I made seems to work just fine.

I took one of our samples like Inventory, added the following to the end of the MainWindow.xaml:
<Border Grid.ColumnSpan="5" Grid.RowSpan="5" Width="200" Height="100" Background="Red" HorizontalAlignment="Left" VerticalAlignment="Top">
  <Border.ToolTip>
    <Border Background="OldLace">
      <TextBlock Text="{Binding ToolTipText}" Foreground="Black" Padding="5" FontSize="18" />
    </Border>
  </Border.ToolTip>
</Border>
Modified ViewModel.cs to include the ToolTipText property:
public class ViewModel : NotifierBase
{
  private string _tooltiptext;
  public string ToolTipText
  {
    get { return _tooltiptext; }
    set
    {
      if (_tooltiptext != value)
      {
        _tooltiptext = value;
        OnPropertyChanged("ToolTipText");
      }
    }
  }
  ...
}
And then added some code in the MainWindow code-behind to change the ToolTip text when the mouse is pressed:
private void OnInitialized(object sender, EventArgs e)
{
  DataContext = new ViewModel();

  ViewModel vm = DataContext as ViewModel;
  vm.ToolTipText = "Hello world";

  this.PreviewMouseDown += (s, e_) =>
  {
    vm.ToolTipText = "ToolTip is changing: " + e_.GetPosition(null);
  };
}
Could you please try that and let us know if it works?

Re: Can't get Tooltip to update

Posted: 30 Dec 2019, 17:24
by Jamieh
I should have the latest Noesis. I will try what you posted. I thought I was already doing that.

I failed to mention that this was in Unity. Sorry-was posting really late.

Re: Can't get Tooltip to update

Posted: 31 Dec 2019, 07:48
by Jamieh
Ok, moral of the story--don't try to make sense of non-working code at 4AM. :)

This is working fine. I just had a really dumb error in my code. Thanks for looking at it, and I'm sorry for wasting your time.

Re: Can't get Tooltip to update

Posted: 03 Jan 2020, 12:25
by sfernandez
Ok, marking this as solved.