NotifyIcon WPF

--------------
CHG   Merged partial classes of TaskbarIcon - no only 2 files.
ADD   Added attached events that indicate an opened popup/tooltip
ADD   Added storyboards in samples that make use of attached events.

git-svn-id: https://svn.evolvesoftware.ch/repos/evolve.net/WPF/NotifyIcon@56 9f600761-6f11-4665-b6dc-0185e9171623
This commit is contained in:
Philipp Sumi
2009-04-01 07:34:50 +00:00
parent 354ba1ca43
commit 1242596214
8 changed files with 682 additions and 618 deletions

View File

@@ -2,8 +2,22 @@
x:Class="Sample_Project.FancyPopup"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:tb="http://www.hardcodet.net/taskbar"
Height="215"
Width="300" x:Name="me">
<UserControl.Resources>
<Storyboard x:Key="RotateIcon">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="image" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
<SplineDoubleKeyFrame KeySpline="0,0.284,0.39,1" KeyTime="00:00:01.4000000" Value="360"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</UserControl.Resources>
<UserControl.Triggers>
<EventTrigger RoutedEvent="tb:TaskbarIcon.PopupOpened">
<BeginStoryboard Storyboard="{StaticResource RotateIcon}" x:Name="RotateIcon_BeginStoryboard"/>
</EventTrigger>
</UserControl.Triggers>
<Grid>
<Border
HorizontalAlignment="Stretch"
@@ -36,7 +50,16 @@
Width="72"
Height="72"
Source="Images\preferences.png"
Stretch="Fill" />
Stretch="Fill" x:Name="image" RenderTransformOrigin="0.5,0.5" >
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="1"/>
<SkewTransform AngleX="0" AngleY="0"/>
<RotateTransform Angle="0"/>
<TranslateTransform X="0" Y="0"/>
</TransformGroup>
</Image.RenderTransform>
</Image>
<TextBlock
Margin="107,10,20,0"
TextWrapping="Wrap"

View File

@@ -3,12 +3,42 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:tb="clr-namespace:Hardcodet.Wpf.TaskbarNotification;assembly=Hardcodet.Wpf.TaskbarNotification"
xmlns:tb="http://www.hardcodet.net/taskbar"
mc:Ignorable="d"
x:Class="Sample_Project.FancyToolTip"
x:Name="me"
Width="285"
Height="108">
<UserControl.Resources>
<Storyboard x:Key="FadeIn">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="border" Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.25"/>
<SplineDoubleKeyFrame KeyTime="00:00:01" Value="1"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="image" Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.6"/>
<SplineDoubleKeyFrame KeyTime="00:00:01" Value="1"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="FadeOut">
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="border" Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
<SplineDoubleKeyFrame KeyTime="00:00:01" Value="0.25"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="image" Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>
<SplineDoubleKeyFrame KeyTime="00:00:01" Value="0.6"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</UserControl.Resources>
<UserControl.Triggers>
<EventTrigger RoutedEvent="tb:TaskbarIcon.ToolTipOpened">
<BeginStoryboard Storyboard="{StaticResource FadeIn}" x:Name="FadeIn_BeginStoryboard"/>
</EventTrigger>
<EventTrigger RoutedEvent="tb:TaskbarIcon.ToolTipClose">
<BeginStoryboard Storyboard="{StaticResource FadeOut}" x:Name="FadeOut_BeginStoryboard"/>
</EventTrigger>
</UserControl.Triggers>
<Grid
x:Name="LayoutRoot">
@@ -19,7 +49,7 @@
Height="Auto"
CornerRadius="6,6,6,6"
BorderThickness="3,3,3,3"
Margin="0,0,5,5">
Margin="0,0,5,5" x:Name="border">
<Border.Effect>
<DropShadowEffect
Color="#FF7A7A7A" />
@@ -44,7 +74,16 @@
Source="Images\Info.png"
Stretch="Fill"
VerticalAlignment="Top"
RenderTransformOrigin="0.792,0.486" />
RenderTransformOrigin="0.792,0.486" x:Name="image" >
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="1"/>
<SkewTransform AngleX="0" AngleY="0"/>
<RotateTransform Angle="0"/>
<TranslateTransform X="0" Y="0"/>
</TransformGroup>
</Image.RenderTransform>
</Image>
<TextBlock
Margin="82,10,20,0"
TextWrapping="Wrap"

View File

@@ -10,6 +10,7 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Hardcodet.Wpf.TaskbarNotification;
namespace Sample_Project
{
@@ -27,7 +28,7 @@ namespace Sample_Project
DependencyProperty.Register("InfoText",
typeof (string),
typeof (FancyToolTip),
new FrameworkPropertyMetadata("", InfoTextPropertyChanged));
new FrameworkPropertyMetadata(""));
/// <summary>
/// A property wrapper for the <see cref="InfoTextProperty"/>
@@ -40,34 +41,6 @@ namespace Sample_Project
set { SetValue(InfoTextProperty, value); }
}
/// <summary>
/// A static callback listener which is being invoked if the
/// <see cref="InfoTextProperty"/> dependency property has
/// been changed. Invokes the <see cref="OnInfoTextPropertyChanged"/>
/// instance method of the changed instance.
/// </summary>
/// <param name="d">The currently processed owner of the property.</param>
/// <param name="e">Provides information about the updated property.</param>
private static void InfoTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
FancyToolTip owner = (FancyToolTip) d;
owner.OnInfoTextPropertyChanged(e);
}
/// <summary>
/// Handles changes of the <see cref="InfoTextProperty"/> dependency property. As
/// WPF internally uses the dependency property system and bypasses the
/// <see cref="InfoText"/> property wrapper, updates of the property's value
/// should be handled here.
/// </summary
/// <param name="e">Provides information about the updated property.</param>
private void OnInfoTextPropertyChanged(DependencyPropertyChangedEventArgs e)
{
// string newValue = (string) e.NewValue;
}
#endregion
@@ -76,5 +49,6 @@ namespace Sample_Project
{
this.InitializeComponent();
}
}
}

View File

@@ -25,117 +25,25 @@
TypeName="tb:PopupActivationMode" />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<Storyboard
x:Key="OnTaskbarIconLeftMouseUp1">
<BooleanAnimationUsingKeyFrames
BeginTime="00:00:00"
Storyboard.TargetName="popup"
Storyboard.TargetProperty="(Popup.IsOpen)">
<DiscreteBooleanKeyFrame
KeyTime="00:00:00"
Value="True" />
<DiscreteBooleanKeyFrame
KeyTime="00:00:02"
Value="False" />
</BooleanAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames
BeginTime="00:00:00"
Storyboard.TargetName="ellipse"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">
<SplineDoubleKeyFrame
KeyTime="00:00:00"
Value="0" />
<SplineDoubleKeyFrame
KeyTime="00:00:01"
Value="74" />
<SplineDoubleKeyFrame
KeyTime="00:00:01.5000000"
Value="26" />
<SplineDoubleKeyFrame
KeyTime="00:00:02"
Value="0" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames
BeginTime="00:00:00"
Storyboard.TargetName="ellipse"
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">
<SplineDoubleKeyFrame
KeyTime="00:00:00"
Value="0" />
<SplineDoubleKeyFrame
KeyTime="00:00:01"
Value="106" />
<SplineDoubleKeyFrame
KeyTime="00:00:01.5000000"
Value="151" />
<SplineDoubleKeyFrame
KeyTime="00:00:02"
Value="0" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames
BeginTime="00:00:00"
Storyboard.TargetName="popup"
Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame
KeyTime="00:00:00"
Value="0.1" />
<SplineDoubleKeyFrame
KeyTime="00:00:02"
Value="1" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames
BeginTime="00:00:00"
Storyboard.TargetName="ellipse"
Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame
KeyTime="00:00:00"
Value="0.47" />
<SplineDoubleKeyFrame
KeyTime="00:00:01"
Value="1" />
<SplineDoubleKeyFrame
KeyTime="00:00:01.5000000"
Value="1" />
<SplineDoubleKeyFrame
KeyTime="00:00:02"
Value="0.685" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames
BeginTime="00:00:00"
Storyboard.TargetName="border"
Storyboard.TargetProperty="(UIElement.Opacity)">
<SplineDoubleKeyFrame
KeyTime="00:00:00"
Value="1" />
<SplineDoubleKeyFrame
KeyTime="00:00:01"
Value="0.515" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<Storyboard x:Key="FadeToolTip"/>
</Window.Resources>
<Window.Triggers>
<EventTrigger
RoutedEvent="tb:TaskbarIcon.TaskbarIconLeftMouseUp"
SourceName="tb">
<BeginStoryboard
Storyboard="{StaticResource OnTaskbarIconLeftMouseUp1}" />
</EventTrigger>
</Window.Triggers>
<Window.Triggers>
<EventTrigger RoutedEvent="tb:TaskbarIcon.TaskbarIconToolTipOpen" SourceName="tb"/>
</Window.Triggers>
<Grid>
<tb:TaskbarIcon
x:Name="tb"
VerticalAlignment="Top"
IconSource="{Binding Path=SelectedItem.Source, ElementName=iconList, Mode=Default}"
ContextMenu="{DynamicResource tbMenu}"
ToolTip="hello world"
ToolTipText="{Binding Path=Text, ElementName=txtToolTipText, Mode=Default}"
Visibility="{Binding Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}, ElementName=iconVisibility, Mode=Default}"
MenuActivation="{Binding Path=SelectedItem, ElementName=lstMenuTrigger, Mode=Default}"
PopupActivation="{Binding Path=SelectedItem, ElementName=lstPopupTrigger, Mode=Default}">
<tb:TaskbarIcon.TaskbarIconPopup>
<!-- the control will be put into a popup with an explicit DataContext -->
<local:FancyPopup />
</tb:TaskbarIcon.TaskbarIconPopup>
@@ -148,6 +56,13 @@
</tb:TaskbarIcon>
<!-- EVERYTHING BELOW IS JUST PLUMBING FOR THE SAMPLE -->
<Button
x:Name="btn"
Click="OnClick"
@@ -165,58 +80,6 @@
VerticalAlignment="Top"
Width="75"
Content="Button" />
<Popup
x:Name="popup"
Margin="-231,-276,231,0"
VerticalAlignment="Top"
Height="549"
d:IsHidden="True"
d:IsLocked="True">
<Grid
Width="180"
Height="227">
<Border
CornerRadius="10,10,10,10"
x:Name="border">
<Border.Background>
<LinearGradientBrush
EndPoint="0.5,1"
StartPoint="0.5,0">
<GradientStop
Color="#FFF4B569"
Offset="0" />
<GradientStop
Color="#FFFFFFFF"
Offset="1" />
</LinearGradientBrush>
</Border.Background>
</Border>
<Ellipse
Fill="#FFC13E3E"
Stroke="#FF000000"
VerticalAlignment="Top"
Height="58"
Margin="51,19,75,0"
x:Name="ellipse"
RenderTransformOrigin="0.5,0.5">
<Ellipse.RenderTransform>
<TransformGroup>
<ScaleTransform
ScaleX="1"
ScaleY="1" />
<SkewTransform
AngleX="0"
AngleY="0" />
<RotateTransform
Angle="0" />
<TranslateTransform
X="0"
Y="0" />
</TransformGroup>
</Ellipse.RenderTransform>
</Ellipse>
</Grid>
</Popup>
<CheckBox
HorizontalAlignment="Left"
Margin="8,116,0,0"
@@ -410,7 +273,7 @@
BorderBrush="#FF000000"
BorderThickness="2,2,2,2" />
<ListBox
Margin="10,0,128,10"
Margin="10,0,95,10"
IsSynchronizedWithCurrentItem="False"
x:Name="lstMenuTrigger"
ItemsSource="{Binding Mode=OneWay, Source={StaticResource ActivationModes}}"
@@ -431,8 +294,6 @@
Height="Auto"
TextWrapping="Wrap"
FontWeight="Bold"
FontSize="14"><Run
Text="This window only contains the plumbing. In order to keep things separated, I created a few user controls for the popups and the TaskbarIcon instance."
Language="de-ch" /></TextBlock>
FontSize="14"><Run Text="Some Title Goes Here..." Language="de-ch"/></TextBlock>
</Grid>
</Window>