Jamieh
Topic Author
Posts: 44
Joined: 12 Apr 2019, 00:30

Can't get Tooltip to update

29 Dec 2019, 10:01

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.

Tags:
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: Can't get Tooltip to update

30 Dec 2019, 10:00

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?
 
Jamieh
Topic Author
Posts: 44
Joined: 12 Apr 2019, 00:30

Re: Can't get Tooltip to update

30 Dec 2019, 17:24

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.
 
Jamieh
Topic Author
Posts: 44
Joined: 12 Apr 2019, 00:30

Re: Can't get Tooltip to update

31 Dec 2019, 07:48

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.
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: Can't get Tooltip to update

03 Jan 2020, 12:25

Ok, marking this as solved.

Who is online

Users browsing this forum: No registered users and 1 guest