Possible issue with bound DataContext (v2.1.0f1 Unity)
Posted: 13 Mar 2018, 05:55
I have a ToolTip created from a UserControl. The ToolTip's DataContext is bound to a property of its parent's DataContext. I am not changing any of these values in codebehind -- they do not change once they are initially set. The value of the ToolTip's DataContext switches back and forth between the parent's property value and null (which seems kind of strange, since I'm not changing its value). The switch to null occurs after the ToolTip closes, when another ToolTip (using a different UserControl class and a DataContext bound to a different property of its parent's DataContext) on the same screen opens. The switch to the parent's property value occurs just before the ToolTip opens. Sometimes, however, the switch doesn't happen and the DataContext gets stuck on the property value (which is okay), but can also get stuck on null (in which case no data shows up in the ToolTip). I can probably work around this by saving the initial DataContext value and then restoring it if it gets stuck on null, but it doesn't seem like it should be behaving this way.
The following is a very simplified version of how the XAML is structured.
Info is a class with information.
InfoView is a UserControl type that visually shows data of the Info type.
CurrentInfo is an instance of the Info type that is a property of Parent's DataContext.
I attached an event handler to DataContextChanged to see what is going on. The event is firing correctly to show when the DataContext is changed. This is the stack trace when DataContext changes:
Void Noesis.FrameworkElement:RaiseDataContextChanged (IntPtr, IntPtr, IntPtr)+0x7d at NoesisGUI\Plugins\API\Proxies\FrameworkElement.cs:190 C#
Void Noesis.View:Noesis_View_Update_ (HandleRef, Double)+0x3 at NoesisGUI\Plugins\API\Core\NoesisView.cs:528 C#
Void Noesis.View:Update (Double)+0x17 at NoesisGUI\Plugins\API\Core\NoesisView.cs:294 C#
Void NoesisView:LateUpdate ()+0x45 at NoesisGUI\Plugins\NoesisView.cs:674 C#
It appears that I can stop the switching from happening after the ToolTip closes if a plain ToolTip (just text) is shown before another non-text ToolTip is shown.
Is there something that I could possibly be doing that causes the DataContext to behave like this, or is this a bug?
Thanks,
Chris
The following is a very simplified version of how the XAML is structured.
Info is a class with information.
InfoView is a UserControl type that visually shows data of the Info type.
CurrentInfo is an instance of the Info type that is a property of Parent's DataContext.
Code: Select all
<UserControl x:Name="Parent">
<Grid>
<Grid.ToolTip>
<local:InfoView DataContext="{Binding CurrentInfo}" />
</Grid.ToolTip>
</Grid>
</UserControl>Void Noesis.FrameworkElement:RaiseDataContextChanged (IntPtr, IntPtr, IntPtr)+0x7d at NoesisGUI\Plugins\API\Proxies\FrameworkElement.cs:190 C#
Void Noesis.View:Noesis_View_Update_ (HandleRef, Double)+0x3 at NoesisGUI\Plugins\API\Core\NoesisView.cs:528 C#
Void Noesis.View:Update (Double)+0x17 at NoesisGUI\Plugins\API\Core\NoesisView.cs:294 C#
Void NoesisView:LateUpdate ()+0x45 at NoesisGUI\Plugins\NoesisView.cs:674 C#
It appears that I can stop the switching from happening after the ToolTip closes if a plain ToolTip (just text) is shown before another non-text ToolTip is shown.
Is there something that I could possibly be doing that causes the DataContext to behave like this, or is this a bug?
Thanks,
Chris