Skip to content

Instantly share code, notes, and snippets.

@julesx
Last active December 23, 2015 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julesx/6690778 to your computer and use it in GitHub Desktop.
Save julesx/6690778 to your computer and use it in GitHub Desktop.
<Window x:Class="WpfApplication5.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<Storyboard x:Key="animate">
<ObjectAnimationUsingKeyFrames BeginTime="0:0:0" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<DoubleAnimation BeginTime="0:0:0.0" Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:0.2"/>
<DoubleAnimation BeginTime="0:0:2.5" Storyboard.TargetProperty="Opacity" From="1" To="0" Duration="0:0:0.5"/>
<ObjectAnimationUsingKeyFrames BeginTime="0:0:5.5" Storyboard.TargetProperty="Visibility">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Hidden</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</Window.Resources>
<StackPanel Orientation="Vertical">
<StackPanel.Resources>
<Style x:Key="HiddenTabItem" TargetType="{x:Type TabItem}">
<EventSetter Event="MouseEnter" Handler="EventSetter_OnHandler" />
<EventSetter Event="MouseLeave" Handler="EventSetter_OnHandler2" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabItem}">
<Border x:Name="TabHeader" BorderThickness="1,1,0,1" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" Padding="{TemplateBinding Padding}">
<ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" HorizontalAlignment="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" VerticalAlignment="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" ContentSource="Header" RecognizesAccessKey="True"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</StackPanel.Resources>
<StackPanel Orientation="Horizontal">
<Border MouseEnter="UIElement_OnMouseEnter" Width="100" Height="100" BorderBrush="Black" BorderThickness="2">
<TextBlock Text="Mouse Over to Show Tabs" TextWrapping="Wrap" HorizontalAlignment="Center" TextAlignment="Center" VerticalAlignment="Center" />
</Border>
</StackPanel>
<TabControl>
<TabItem Name="Tab1" Style="{StaticResource HiddenTabItem}" Visibility="Hidden" Header="Tab 1">
<Border Width="100" Height="100" BorderBrush="Red" BorderThickness="2">
<TextBlock Text="Random content that should not affect tabs whatsoever" TextAlignment="Center" VerticalAlignment="Center" HorizontalAlignment="Center" TextWrapping="Wrap" />
</Border>
</TabItem>
<TabItem Name="Tab2" Style="{StaticResource HiddenTabItem}" Visibility="Hidden" Header="Tab 2">
<Border Width="100" Height="100" BorderBrush="Violet" BorderThickness="2">
<TextBlock Text="Random content that should not affect tabs whatsoever" TextAlignment="Center" VerticalAlignment="Center" HorizontalAlignment="Center" TextWrapping="Wrap" />
</Border>
</TabItem>
</TabControl>
</StackPanel>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication5
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void UIElement_OnMouseEnter(object sender, MouseEventArgs e)
{
((Storyboard)FindResource("animate")).Begin(Tab1, true);
((Storyboard)FindResource("animate")).Begin(Tab2, true);
}
private void EventSetter_OnHandler(object sender, MouseEventArgs e)
{
var tabItem = (TabItem) sender;
if (tabItem.HasAnimatedProperties)
{
((Storyboard)FindResource("animate")).Pause(Tab1);
((Storyboard)FindResource("animate")).Pause(Tab2);
}
}
private void EventSetter_OnHandler2(object sender, MouseEventArgs e)
{
var tabItem = (TabItem) sender;
if (tabItem.HasAnimatedProperties)
{
((Storyboard)FindResource("animate")).Resume(Tab1);
((Storyboard)FindResource("animate")).Resume(Tab2);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment