unoplatform / uno

Open-source platform for building cross-platform native Mobile, Web, Desktop and Embedded apps quickly. Create rich, C#/XAML, single-codebase apps from any IDE. Hot Reload included! 90m+ NuGet Downloads!!
https://platform.uno
Apache License 2.0
8.87k stars 716 forks source link

Tooltip `DataContext` is not propagated properly #3028

Closed jeromelaban closed 1 year ago

jeromelaban commented 4 years ago

Current behavior

The datacontext of the host of the ToolTip does not propagate the value properly.

How to reproduce it (as minimally and precisely as possible)

https://playgroundcanary.z19.web.core.windows.net/#ccd0d76f

<Button Content="{Binding}">
  <ToolTipService.ToolTip>
    <ToolTip Content="{Binding}" Width="350" Height="60"/>
  </ToolTipService.ToolTip>
</Button>

Workaround

Forwarding the DataContext manually using an ElementName can be used as a workaround:

<Button Content="Test"  x:Name="buttonTest">
  <ToolTipService.ToolTip>
    <ToolTip DataContext="{Binding DataContext, ElementName=buttonTest}" Content="{Binding message}" Width="350" Height="60"/>
  </ToolTipService.ToolTip>
</Button>

Environment

Nuget Package:

Package Version(s):

Affected platform(s):

Visual Studio:

Relevant plugins:

Anything else we need to know?

ramezgerges commented 1 year ago

This looks fixed to me.

    <Button x:Name="btn" Content="{Binding}" DataContext="button DC">
        <ToolTipService.ToolTip>
            <ToolTip x:Name="tt" Content="{Binding}" Width="350" Height="60"/>
        </ToolTipService.ToolTip>
    </Button>

image

I also tried setting the DataContext in the code behind instead of directly in the xaml. Still works.