Files
wpf-notifyicon/Source/Sample Project/Window1.xaml
Philipp Sumi 98a0017687 WPF NotifyIcon : Public Release
-------------------------------
CHG   Common cleanup, copyright etc.
DEL   Removed unused dependency property change handlers.
ADD   Added ResetBalloonCloseTimer method which keeps custom balloons open.
ADD   Provided implementation for attached BalloonClosingEvent.

git-svn-id: https://svn.evolvesoftware.ch/repos/evolve.net/WPF/NotifyIcon@94 9f600761-6f11-4665-b6dc-0185e9171623
2009-05-04 19:36:22 +00:00

392 lines
14 KiB
XML

<Window
x:Class="Sample_Project.Window1"
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"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="WPF NotifyIcon Sample"
Height="833"
Width="769"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:local="clr-namespace:Sample_Project"
xmlns:Commands="clr-namespace:Sample_Project.Commands" MinWidth="750" MinHeight="800" ResizeMode="NoResize">
<Window.Resources>
<BooleanToVisibilityConverter
x:Key="BooleanToVisibilityConverter" />
<ObjectDataProvider
MethodName="GetValues"
ObjectType="{x:Type sys:Enum}"
x:Key="ActivationModes">
<ObjectDataProvider.MethodParameters>
<x:Type
TypeName="tb:PopupActivationMode" />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</Window.Resources>
<Window.Background>
<LinearGradientBrush
EndPoint="0.5,1"
StartPoint="0.5,0">
<GradientStop
Color="#FFFFFFFF"
Offset="0" />
<GradientStop
Color="#FFFFE7D1"
Offset="1" />
</LinearGradientBrush>
</Window.Background>
<Window.Triggers>
<EventTrigger
RoutedEvent="tb:TaskbarIcon.TrayToolTipOpen"
SourceName="tb" />
</Window.Triggers>
<Grid>
<!--
THE TASKBARICON ELEMENT WAS DECLARED INLINE IN ORDER TO USE DATABINDING
FOR ITS PROPERTIES. IN A REAL-LIFE APP, YOU'D PROBABLY RATHER DECLARE
IT IN A RESOURCE DICTIONARY SO YOU CAN EVEN USE IT IF THERE IS NO WINDOW
OPEN.
-->
<tb:TaskbarIcon
x:Name="tb"
VerticalAlignment="Top"
IconSource="{Binding Path=SelectedItem.Source, ElementName=iconList, Mode=Default}"
ContextMenu="{DynamicResource tbMenu}"
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}"
DoubleClickCommand="{Commands:ShowMainWindowCommand}"
>
<tb:TaskbarIcon.TrayPopup>
<!-- the control will be put into a popup with an explicit DataContext -->
<local:FancyPopup />
</tb:TaskbarIcon.TrayPopup>
<tb:TaskbarIcon.TrayToolTip>
<!-- the control will be put into a tooltip with an explicit DataContext -->
<local:FancyToolTip
Opacity="0.85"
InfoText="{Binding Path=ToolTipText}" />
</tb:TaskbarIcon.TrayToolTip>
</tb:TaskbarIcon>
<!-- EVERYTHING BELOW IS JUST PLUMBING FOR THE SAMPLE -->
<CheckBox
HorizontalAlignment="Left"
Margin="10,38.62,0,0"
VerticalAlignment="Top"
Width="155.42"
Content="NotifyIcon Visible"
x:Name="iconVisibility"
IsChecked="True" />
<ListBox
HorizontalAlignment="Left"
Margin="12,86.58,0,0"
Width="123"
IsSynchronizedWithCurrentItem="True"
Height="51"
VerticalAlignment="Top"
x:Name="iconList"
SelectedIndex="0">
<Image
Width="16"
Margin="0,4,0,0"
Height="16"
Source="Icons\Inactive.ico" />
<Image
Width="16"
Margin="0,4,0,0"
Height="16"
Source="Icons\Error.ico" />
</ListBox>
<TextBlock
HorizontalAlignment="Left"
Margin="12,64.58,0,0"
VerticalAlignment="Top"
Width="Auto"
Height="22"
TextWrapping="Wrap"><Run
Text="Taskbar Icon:"
Language="de-ch" /></TextBlock>
<Grid
Margin="0,544.58,10,0"
VerticalAlignment="Top"
Height="210"
Width="358"
HorizontalAlignment="Right"
x:Name="Balloons">
<Border
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
BorderBrush="#FF000000"
BorderThickness="2,2,2,2" />
<TextBox
Margin="125,0,17,133"
x:Name="txtBalloonTitle"
VerticalAlignment="Bottom"
Height="23">WPF NotifyIcon</TextBox>
<TextBox
Margin="125,0,17,76"
x:Name="txtBalloonText" AcceptsReturn="True" Height="47" VerticalAlignment="Bottom" d:LayoutOverrides="VerticalAlignment"
TextWrapping="Wrap" Text="You should see a LED icon in your system tray. This is your NotifyIcon."/>
<RadioButton
HorizontalAlignment="Left"
Margin="14,0,0,54"
VerticalAlignment="Bottom"
Width="111"
Height="22"
Content="Show as Info"
IsChecked="True"
x:Name="rbInfo" />
<TextBlock
HorizontalAlignment="Left"
Margin="14,0,0,133"
VerticalAlignment="Bottom"
Width="85"
Height="23"
TextWrapping="Wrap"><Run
Text="Balloon Title"
Language="de-ch" /></TextBlock>
<TextBlock
Margin="14,0,0,100"
TextWrapping="Wrap"
HorizontalAlignment="Left"
Width="85" Height="23" VerticalAlignment="Bottom" d:LayoutOverrides="VerticalAlignment"><Run
Text="Balloon Text"
Language="de-ch" /></TextBlock>
<RadioButton
Margin="14,0,0,32"
VerticalAlignment="Bottom"
Height="22"
Content="Show as Error"
HorizontalAlignment="Left"
Width="111"
x:Name="rbError" />
<RadioButton
Margin="14,0,0,10"
VerticalAlignment="Bottom"
Height="22"
Content="Show Custom Icon"
HorizontalAlignment="Left"
Width="130"
x:Name="rbCustomIcon" />
<Button
HorizontalAlignment="Right"
Margin="0,0,17,43"
x:Name="showBalloonTip"
Width="120"
Content="Show Balloon Tip"
VerticalAlignment="Bottom"
Height="23"
Click="showBalloonTip_Click" />
<TextBlock
Margin="14,10,17,0"
VerticalAlignment="Top"
Height="33"
TextWrapping="Wrap"><Run
Text="Standard balloon tips. You can use custom icons under all OS versions."
Language="de-ch" /></TextBlock>
<Button
HorizontalAlignment="Right"
Margin="0,0,17,12.52"
x:Name="hideBalloonTip"
Width="120"
Content="Hide Balloon Tip"
VerticalAlignment="Bottom"
Height="23"
Click="hideBalloonTip_Click" />
</Grid>
<Grid
HorizontalAlignment="Left"
Margin="12,512.58,0,0"
VerticalAlignment="Top"
Width="307"
Height="242"
x:Name="Popups">
<Border
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
BorderBrush="#FF000000"
BorderThickness="2,2,2,2" />
<ListBox
IsSynchronizedWithCurrentItem="False"
x:Name="lstPopupTrigger"
ItemsSource="{Binding Mode=OneWay, Source={StaticResource ActivationModes}}"
Margin="14,115,97,10"
SelectedIndex="0" />
<TextBlock
Margin="14,10,10,0"
TextWrapping="Wrap"
VerticalAlignment="Top"
Height="105"><Run
Text="If the user clicks on the Taskbar Icon, a popup can be opened and displayed. Unlike custom ToolTips, this works under Windows xp as well. In case left-clicks are used, popups are displayed with a delay to ensure the user does not double-click. Trigger is determined by the "
Language="de-ch" /><Run
FontStyle="Italic"
FontWeight="Bold"
Text="PopupActivation "
Language="de-ch" /><Run
Text="property."
Language="de-ch" /></TextBlock>
</Grid>
<Grid
Margin="0,156.38,10,0"
Width="358"
HorizontalAlignment="Right"
x:Name="ToolTips" Height="233" VerticalAlignment="Top" d:LayoutOverrides="VerticalAlignment">
<Border
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
BorderBrush="#FF000000"
BorderThickness="2,2,2,2" />
<TextBox
Margin="10,0,25,70"
x:Name="txtToolTipText"
VerticalAlignment="Bottom"
Height="23"
Text="THIS IS A SAMPLE TEXT...."
Foreground="#FFFF0000" />
<TextBlock
Margin="10,0,25,93"
TextWrapping="Wrap" Height="21" VerticalAlignment="Bottom"><Run
Text="ToolTipText:"
Language="de-ch" /></TextBlock>
<TextBlock
Margin="10,10,10,0"
VerticalAlignment="Top"
Height="112"
TextWrapping="Wrap"><Run
Text="If the user moves the mouse over the Taskbar Icon, a tooltip can be displayed. Starting from Windows Vista, we have convenient events to display and hide tooltips. If we can, the "
Language="de-ch" /><Run
FontStyle="Italic"
FontWeight="Bold"
Text="TrayToolTip "
Language="de-ch" /><Run
Text="control is being displayed."
Language="de-ch" /><LineBreak /><Run
Text="If "
Language="de-ch" /><Run
FontStyle="Italic"
FontWeight="Bold"
Text="TrayToolTip "
Language="de-ch" /><Run
Text="is not set or the app runs under an older OS (e.g. xp), the control falls back to the "
Language="de-ch" /><Run
FontStyle="Italic"
FontWeight="Bold"
Text="ToolTipText "
Language="de-ch" /><Run
Text="property."
Language="de-ch" /></TextBlock>
<Button
HorizontalAlignment="Left"
Margin="10,0,0,10"
VerticalAlignment="Bottom"
Width="147"
Height="24"
Content="Remove Custom ToolTip"
Name="removeToolTip"
Click="removeToolTip_Click" />
<TextBlock
Margin="10,0,25,44"
VerticalAlignment="Bottom"
Height="16"
TextWrapping="Wrap"><Run
Text="Click to fall back to ToolTipText (sets TrayToolTip to null):"
Language="de-ch" /></TextBlock>
</Grid>
<Grid
HorizontalAlignment="Left"
Margin="12,231.58,0,0"
Width="307"
x:Name="ContextMenus" Height="271" VerticalAlignment="Top">
<Border
BorderBrush="#FF000000"
BorderThickness="2,2,2,2" />
<ListBox
Margin="10,0,95,10"
IsSynchronizedWithCurrentItem="False"
x:Name="lstMenuTrigger"
ItemsSource="{Binding Mode=OneWay, Source={StaticResource ActivationModes}}"
Height="124"
VerticalAlignment="Bottom"
SelectedIndex="1" />
<TextBlock
Margin="10,108,48,0"
VerticalAlignment="Top"
Height="22"
TextWrapping="Wrap"><Run
Text="Mouse events that open the context menu:"
Language="de-ch" /></TextBlock>
<TextBlock
Margin="10,10,10,0"
VerticalAlignment="Top"
Height="78"
TextWrapping="Wrap"><Run
Text="Assign a custon context menu through the "
Language="de-ch" /><Run
FontStyle="Italic"
FontWeight="Bold"
Text="ContextMenu "
Language="de-ch" /><Run
Text="property of the TaskbarIcon. The "
Language="de-ch" /><Run
FontStyle="Italic"
FontWeight="Bold"
Text="MenuActivation "
Language="de-ch" /><Run
Text="property determines what mouse events open the context menu."
Language="de-ch" /></TextBlock>
</Grid>
<TextBlock
Margin="10,10,0,0"
VerticalAlignment="Top"
Height="Auto"
TextWrapping="Wrap"
FontWeight="Bold"
FontSize="14" Width="309" HorizontalAlignment="Left"><Run
Text="WPF NotifyIcon - RC 1.0"
Language="de-ch" /></TextBlock>
<TextBlock
HorizontalAlignment="Right"
Margin="0,10,10,0"
VerticalAlignment="Top"
Width="358"
Height="146.38"
FontSize="14"
FontStyle="Italic"
Foreground="#FF303030"
TextWrapping="Wrap"><Run Text="This is my first shot at this control and a think a few additions might make sense." Language="de-ch"/><LineBreak/><Run Text="Play around and feel free to commit critical feedback - it's appreciated :)" Language="de-ch"/><LineBreak/><Run Text="" Language="de-ch"/><LineBreak/><Run Foreground="#FF067EBD" Text="Feedback and Updates:" Language="de-ch"/><LineBreak/><Run Foreground="#FF067EBD" Text="http://www.hardcodet.net " Language="de-ch"/><Run FontSize="10" Foreground="#FF067EBD" Text="(watch the spelling" Language="de-ch"/><Run Foreground="#FF067EBD" Text=")" Language="de-ch"/></TextBlock>
<TextBlock Margin="12,0,10,10" VerticalAlignment="Bottom" Height="22.42" TextWrapping="Wrap" FontWeight="Bold" Foreground="#FFFFA051"><Run Text="Copyright (c) 2009 Philipp Sumi. This is prerelease software, realeased under the CodeProject Open License (CPOL)" Language="de-ch"/></TextBlock>
<Grid HorizontalAlignment="Right" Margin="0,399.38,10,272.42" Width="358" x:Name="CustomBalloons">
<Border HorizontalAlignment="Stretch" Width="Auto" BorderThickness="2,2,2,2" BorderBrush="#FF000000"/>
<Button Content="Show" x:Name="showCustomBalloon"
Click="showCustomBalloon_Click" HorizontalAlignment="Right" Margin="0,0,91.377,10" Width="71.623" Height="23" VerticalAlignment="Bottom" />
<TextBox VerticalAlignment="Bottom" Height="23" Text="WPF Balloon" TextWrapping="Wrap" Margin="10,0,173,10" x:Name="customBalloonTitle"/>
<TextBlock Margin="10,10,24.377,0" VerticalAlignment="Top" TextWrapping="Wrap" Height="66.68"><Run Text="Custom Balloon Tips are more flexible then standard tips when it comes to styling and they provide attached properties and events that can be used to control behavior. Hover over the tooltip to suspend the fade-out." Language="de-ch"/></TextBlock>
<Button Content="Close" x:Name="hideCustomBalloon"
Click="hideCustomBalloon_Click" HorizontalAlignment="Right" Margin="0,0,9.754,10.52" Width="71.623" Height="23" VerticalAlignment="Bottom" />
</Grid>
</Grid>
</Window>