I am using XamTabControl to develop a screen that looks like Vista's task bar. I want to have the tooltip for each tab to show the small visual of the contents. I am using following XAML but not getting the desired results. Any idea, how do I make it work?
<igWindows:XamTabControl x:Name="xamTab" TabItemCloseButtonVisibility="Visible" DockPanel.Dock="Top" Background="Transparent"> <igWindows:XamTabControl.ItemContainerStyle> <Style TargetType="{x:Type igWindows:TabItemEx }"> <Setter Property="ToolTip"> <Setter.Value> <ControlTemplate TargetType="{x:Type ToolTip}"> <StackPanel> <Rectangle Width="100" Height="75"> <Rectangle.Fill> <VisualBrush Stretch="Fill" Visual="{Binding Content}"/> </Rectangle.Fill> </Rectangle> </StackPanel> </ControlTemplate> </Setter.Value> </Setter> </Style> </igWindows:XamTabControl.ItemContainerStyle></igWindows:XamTabControl>
After my initial post, I was working on same lines. Thanks for confirmation. Fortunately, this approch works even for non-active tabs and surprisingly visuals gets refreshed if I change contents (type some text in text boxes etc.). The only limitation I am seeing right now is that visual brush does not do it's job if content has a frame control. There are work arounds to this problem as well, for example
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/26fb22e6-3952-4ea3-a586-2bb65eec97bf
If there is a better way to take visuals of GDI based objects, please let me know.
Here is my complete code, just in case
<Window.Resources> <ToolTip x:Key="resKWIC" DataContext="{Binding Path=PlacementTarget, RelativeSource={x:Static RelativeSource.Self}}"> <Rectangle Width="100" Height="70" > <Rectangle.Fill> <VisualBrush Stretch="Fill" Visual="{Binding Path=Content}"/> </Rectangle.Fill> </Rectangle> </ToolTip> <PopupAnimation x:Key="{x:Static SystemParameters.ToolTipPopupAnimationKey}">Slide</PopupAnimation></Window.Resources>
<igWindows:XamTabControl x:Name="xamTab" cal:RegionManager.RegionName="ContentRegion" TabItemCloseButtonVisibility="Visible" DockPanel.Dock="Top" Background="Transparent" TabStripPlacement="Bottom"> <igWindows:XamTabControl.ItemContainerStyle> <Style TargetType="{x:Type igWindows:TabItemEx }"> <Setter Property="Header" Value="{Binding Content.DataContext.HeaderInfo}" /> <Setter Property="ToolTip" Value="{StaticResource resKWIC}"/> </Style> </igWindows:XamTabControl.ItemContainerStyle></igWindows:XamTabControl>
In WPF, you can't set a ToolTip to a ControlTemplate - it won't interpret that as using that template to hydrate an instance of that element. In addition, a ToolTip does not pick up the target element as its datacontext so the binding to Content wouldn't work. You can get further by defining the tooltip in the resources as follows but only the content of the selected tab is actually in the visual tree so until you have actually navigated to the tab items, the elements in the tooltip won't really look right and even then the results of the Visual Brush will be based on the last time the content was measured.