mirror of
https://github.com/ckaczor/wpf-notifyicon.git
synced 2026-01-14 01:25:45 -05:00
CHG Moved files to new root folder.
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
<ResourceDictionary 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">
|
||||
|
||||
<!-- Globally declared notify icon (ResourceDictionary is not in use, example only) -->
|
||||
<tb:TaskbarIcon x:Key="MyNotifyIcon"
|
||||
IconSource="/Icons/Error.ico"
|
||||
ToolTipText="hello world" />
|
||||
|
||||
</ResourceDictionary>
|
||||
@@ -0,0 +1,20 @@
|
||||
<Window
|
||||
x:Class="Samples.Tutorials.SimpleWindowWithNotifyIcon"
|
||||
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="300"
|
||||
Width="300">
|
||||
<Grid>
|
||||
|
||||
<!-- in order to declare a NotifyIcon, all you need is the namespace declaration (see above on line 5) and a single line -->
|
||||
<tb:TaskbarIcon x:Name="MyNotifyIcon" IconSource="/Icons/Error.ico" ToolTipText="hello world" />
|
||||
|
||||
<TextBlock Margin="26,26,24,0"
|
||||
VerticalAlignment="Top"
|
||||
FontWeight="Bold"
|
||||
TextWrapping="Wrap"
|
||||
Text="You should see an icon in the tray." />
|
||||
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,23 @@
|
||||
using System.Windows;
|
||||
|
||||
namespace Samples.Tutorials
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for SimpleWindowWithNotifyIcon.xaml
|
||||
/// </summary>
|
||||
public partial class SimpleWindowWithNotifyIcon : Window
|
||||
{
|
||||
public SimpleWindowWithNotifyIcon()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
//clean up notifyicon (would otherwise stay open until application finishes)
|
||||
MyNotifyIcon.Dispose();
|
||||
|
||||
base.OnClosing(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<Window
|
||||
x:Class="Samples.Tutorials.ToolTips.InlineToolTipWindow"
|
||||
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="300"
|
||||
Width="300">
|
||||
<Grid>
|
||||
|
||||
<tb:TaskbarIcon
|
||||
x:Name="MyNotifyIcon"
|
||||
IconSource="/Icons/Error.ico"
|
||||
ToolTipText="hello world">
|
||||
|
||||
<!--
|
||||
We can use arbitrary UI elements as ToolTips.
|
||||
Let's use a semi-transparent border.
|
||||
-->
|
||||
<tb:TaskbarIcon.TrayToolTip>
|
||||
<Border
|
||||
Background="White"
|
||||
BorderBrush="Orange"
|
||||
BorderThickness="2"
|
||||
CornerRadius="4"
|
||||
Opacity="0.8"
|
||||
Width="160"
|
||||
Height="40">
|
||||
<TextBlock
|
||||
Text="hello world"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center" />
|
||||
</Border>
|
||||
</tb:TaskbarIcon.TrayToolTip>
|
||||
|
||||
</tb:TaskbarIcon>
|
||||
<TextBlock Margin="26,26,24,0" VerticalAlignment="Top" FontWeight="Bold" TextWrapping="Wrap">
|
||||
<Run Text="Move mouse over NotifyIcon to show ToolTip" Language="de-ch" />
|
||||
</TextBlock>
|
||||
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,34 @@
|
||||
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.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace Samples.Tutorials.ToolTips
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for Window1.xaml
|
||||
/// </summary>
|
||||
public partial class InlineToolTipWindow : Window
|
||||
{
|
||||
public InlineToolTipWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
//clean up notifyicon (would otherwise stay open until application finishes)
|
||||
MyNotifyIcon.Dispose();
|
||||
|
||||
base.OnClosing(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<UserControl
|
||||
x:Class="Samples.Tutorials.ToolTips.SimpleUserControl"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
|
||||
<!-- a simple user control which displays a fixed text within a border -->
|
||||
<Border
|
||||
Background="White"
|
||||
BorderBrush="Orange"
|
||||
BorderThickness="2"
|
||||
CornerRadius="4"
|
||||
Opacity="0.8"
|
||||
Width="160"
|
||||
Height="40">
|
||||
<TextBlock
|
||||
Text="hello world"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center" />
|
||||
</Border>
|
||||
|
||||
</UserControl>
|
||||
@@ -0,0 +1,27 @@
|
||||
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.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace Samples.Tutorials.ToolTips
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for SimpleUserControl.xaml
|
||||
/// </summary>
|
||||
public partial class SimpleUserControl : UserControl
|
||||
{
|
||||
public SimpleUserControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<Window
|
||||
x:Class="Samples.Tutorials.ToolTips.UserControlToolTipWindow"
|
||||
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:local="clr-namespace:Samples.Tutorials.ToolTips"
|
||||
Height="300"
|
||||
Width="300">
|
||||
<Grid>
|
||||
|
||||
<tb:TaskbarIcon
|
||||
x:Name="MyNotifyIcon"
|
||||
IconSource="/Icons/Error.ico"
|
||||
ToolTipText="hello world">
|
||||
|
||||
<!-- assign user control as ToolTip -->
|
||||
<tb:TaskbarIcon.TrayToolTip>
|
||||
<local:SimpleUserControl />
|
||||
</tb:TaskbarIcon.TrayToolTip>
|
||||
|
||||
</tb:TaskbarIcon>
|
||||
<TextBlock Margin="26,26,24,0" VerticalAlignment="Top" FontWeight="Bold" TextWrapping="Wrap">
|
||||
<Run Text="Move mouse over NotifyIcon to show ToolTip" Language="de-ch" />
|
||||
</TextBlock>
|
||||
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,34 @@
|
||||
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.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace Samples.Tutorials.ToolTips
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for UserControlToolTipWindow.xaml
|
||||
/// </summary>
|
||||
public partial class UserControlToolTipWindow : Window
|
||||
{
|
||||
public UserControlToolTipWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
//clean up notifyicon (would otherwise stay open until application finishes)
|
||||
MyNotifyIcon.Dispose();
|
||||
|
||||
base.OnClosing(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<Window
|
||||
x:Class="Samples.Tutorials.Popups.InlinePopupWindow"
|
||||
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:commands="clr-namespace:Samples.Commands"
|
||||
Height="300"
|
||||
Width="300">
|
||||
<Grid>
|
||||
|
||||
<tb:TaskbarIcon
|
||||
x:Name="MyNotifyIcon"
|
||||
IconSource="/Icons/Error.ico"
|
||||
ToolTipText="hello world">
|
||||
|
||||
<!--
|
||||
We can use arbitrary UI elements as Popups.
|
||||
Popups stay open if the user moves away from the tray area
|
||||
-->
|
||||
<tb:TaskbarIcon.TrayPopup>
|
||||
<Border
|
||||
Background="White"
|
||||
BorderBrush="Orange"
|
||||
BorderThickness="2"
|
||||
CornerRadius="4"
|
||||
Width="160">
|
||||
<StackPanel>
|
||||
<TextBox
|
||||
x:Name="popupText"
|
||||
Margin="5,10,5,10"
|
||||
Width="200"
|
||||
Height="24"
|
||||
Text="Enter Text..." />
|
||||
<Button
|
||||
Content="Click Me!"
|
||||
Command="{commands:CloseWindowCommand}"
|
||||
CommandParameter="{Binding}"
|
||||
Margin="5,0,5,10"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</tb:TaskbarIcon.TrayPopup>
|
||||
|
||||
</tb:TaskbarIcon>
|
||||
<TextBlock
|
||||
Margin="26,26,24,0"
|
||||
VerticalAlignment="Top"
|
||||
FontWeight="Bold"
|
||||
Text="Left-Click NotifyIcon to open popup." />
|
||||
|
||||
<TextBlock
|
||||
Text="Text on Popup: "
|
||||
Margin="26,66,24,0"
|
||||
VerticalAlignment="Top">
|
||||
<TextBlock Foreground="Red"
|
||||
Text="{Binding ElementName=popupText, Path=Text}" />
|
||||
</TextBlock>
|
||||
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,34 @@
|
||||
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.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace Samples.Tutorials.Popups
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for InlinePopupWindow.xaml
|
||||
/// </summary>
|
||||
public partial class InlinePopupWindow : Window
|
||||
{
|
||||
public InlinePopupWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
//clean up notifyicon (would otherwise stay open until application finishes)
|
||||
MyNotifyIcon.Dispose();
|
||||
|
||||
base.OnClosing(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<Window x:Class="Samples.Tutorials.ContextMenus.InlineContextMenuWindow"
|
||||
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:commands="clr-namespace:Samples.Commands"
|
||||
Height="300"
|
||||
Width="300">
|
||||
<Grid>
|
||||
|
||||
<tb:TaskbarIcon x:Name="MyNotifyIcon"
|
||||
IconSource="/Icons/Error.ico"
|
||||
ToolTipText="hello world"
|
||||
TrayContextMenuOpen="MyNotifyIcon_TrayContextMenuOpen"
|
||||
PreviewTrayContextMenuOpen="MyNotifyIcon_PreviewTrayContextMenuOpen">
|
||||
|
||||
<!-- Set a simple context menu -->
|
||||
<!-- the data context of the context menu is the NotifyIcon itself (see more about this in DataBinding samples) -->
|
||||
<tb:TaskbarIcon.ContextMenu>
|
||||
<ContextMenu>
|
||||
<TextBlock Text="Hiding the sample window will not close it!" />
|
||||
<MenuItem Header="_Show Sample Window [S]"
|
||||
Command="{commands:ShowSampleWindowCommand}"
|
||||
CommandParameter="{Binding}">
|
||||
<MenuItem.Icon>
|
||||
<Image Width="16"
|
||||
Height="16"
|
||||
Source="/Images/Add.png" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
|
||||
<Separator />
|
||||
|
||||
<MenuItem Header="_Hide Sample Window [H]"
|
||||
Command="{commands:HideSampleWindowCommand}"
|
||||
CommandParameter="{Binding}">
|
||||
<MenuItem.Icon>
|
||||
<Image Width="16"
|
||||
Height="16"
|
||||
Source="/Images/Remove.png" />
|
||||
</MenuItem.Icon>
|
||||
</MenuItem>
|
||||
</ContextMenu>
|
||||
</tb:TaskbarIcon.ContextMenu>
|
||||
|
||||
</tb:TaskbarIcon>
|
||||
<TextBlock Margin="26,26,24,0"
|
||||
VerticalAlignment="Top"
|
||||
FontWeight="Bold"
|
||||
TextWrapping="Wrap">
|
||||
<Run Language="de-ch"
|
||||
Text="Right-click on NotifyIcon to open Context Menu" />
|
||||
</TextBlock>
|
||||
<TextBlock HorizontalAlignment="Left"
|
||||
Margin="26,83,0,0"
|
||||
TextWrapping="Wrap"
|
||||
Text="Context menu preview open events:"
|
||||
VerticalAlignment="Top" />
|
||||
<TextBlock HorizontalAlignment="Left"
|
||||
Margin="26,103.96,0,0"
|
||||
TextWrapping="Wrap"
|
||||
Text="Context menu open events:"
|
||||
VerticalAlignment="Top" />
|
||||
<TextBlock x:Name="PreviewOpenEventCounter"
|
||||
HorizontalAlignment="Left"
|
||||
Margin="246,83,0,0"
|
||||
TextWrapping="Wrap"
|
||||
Text="0"
|
||||
VerticalAlignment="Top" />
|
||||
<TextBlock x:Name="OpenEventCounter"
|
||||
HorizontalAlignment="Left"
|
||||
Margin="246,106.97,0,0"
|
||||
TextWrapping="Wrap"
|
||||
Text="0"
|
||||
VerticalAlignment="Top" />
|
||||
<CheckBox x:Name="SuppressContextMenu"
|
||||
Content="Suppress context menu in preview event"
|
||||
HorizontalAlignment="Left"
|
||||
Margin="26,190,0,0"
|
||||
VerticalAlignment="Top" />
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,40 @@
|
||||
using System.Diagnostics;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Samples.Tutorials.ContextMenus
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for InlineContextMenuWindow.xaml
|
||||
/// </summary>
|
||||
public partial class InlineContextMenuWindow : Window
|
||||
{
|
||||
public InlineContextMenuWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
|
||||
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
//clean up notifyicon (would otherwise stay open until application finishes)
|
||||
MyNotifyIcon.Dispose();
|
||||
|
||||
base.OnClosing(e);
|
||||
}
|
||||
|
||||
private void MyNotifyIcon_TrayContextMenuOpen(object sender, System.Windows.RoutedEventArgs e)
|
||||
{
|
||||
OpenEventCounter.Text = (int.Parse(OpenEventCounter.Text) + 1).ToString();
|
||||
}
|
||||
|
||||
private void MyNotifyIcon_PreviewTrayContextMenuOpen(object sender, System.Windows.RoutedEventArgs e)
|
||||
{
|
||||
//marking the event as handled suppresses the context menu
|
||||
e.Handled = (bool) SuppressContextMenu.IsChecked;
|
||||
|
||||
PreviewOpenEventCounter.Text = (int.Parse(PreviewOpenEventCounter.Text) + 1).ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<Window
|
||||
x:Class="Samples.Tutorials.Balloons.BalloonSampleWindow"
|
||||
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="300"
|
||||
Width="300">
|
||||
<Grid>
|
||||
|
||||
<!-- the ToolTipText property is bound to the TextBox below -->
|
||||
<tb:TaskbarIcon
|
||||
x:Name="MyNotifyIcon"
|
||||
IconSource="/Icons/Error.ico"
|
||||
ToolTipText="Balloon Sample Icon" />
|
||||
<Button
|
||||
x:Name="btnShowStandardBalloon"
|
||||
Click="btnShowStandardBalloon_Click"
|
||||
Margin="26,74,29,0"
|
||||
Content="Show Standard Balloon" Height="29" VerticalAlignment="Top" />
|
||||
<Button
|
||||
x:Name="btnShowCustomBalloon"
|
||||
Click="btnShowCustomBalloon_Click"
|
||||
Margin="26,0,29,49"
|
||||
VerticalAlignment="Bottom"
|
||||
Height="27"
|
||||
Content="Show Custom Balloon" />
|
||||
<TextBlock
|
||||
Margin="26,26,24,0"
|
||||
VerticalAlignment="Top"
|
||||
FontWeight="Bold"
|
||||
TextWrapping="Wrap">
|
||||
<Run
|
||||
Language="de-ch"
|
||||
Text="Clicking on buttons shows balloon tips" />
|
||||
</TextBlock>
|
||||
<Button
|
||||
x:Name="btnHideStandardBalloon"
|
||||
Click="btnHideStandardBalloon_Click"
|
||||
Margin="26,113,29,122"
|
||||
Content="Hide Standard Balloon" />
|
||||
<Button
|
||||
x:Name="btnCloseCustomBalloon"
|
||||
Click="btnCloseCustomBalloon_Click"
|
||||
Margin="26,0,29,12"
|
||||
VerticalAlignment="Bottom"
|
||||
Height="27"
|
||||
Content="Close Custom Balloon" />
|
||||
|
||||
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
using Hardcodet.Wpf.TaskbarNotification;
|
||||
|
||||
namespace Samples.Tutorials.Balloons
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for BalloonSampleWindow.xaml
|
||||
/// </summary>
|
||||
public partial class BalloonSampleWindow : Window
|
||||
{
|
||||
public BalloonSampleWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
//clean up notifyicon (would otherwise stay open until application finishes)
|
||||
MyNotifyIcon.Dispose();
|
||||
|
||||
base.OnClosing(e);
|
||||
}
|
||||
|
||||
|
||||
private void btnShowCustomBalloon_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
FancyBalloon balloon = new FancyBalloon();
|
||||
balloon.BalloonText = "Custom Balloon";
|
||||
|
||||
//show balloon and close it after 4 seconds
|
||||
MyNotifyIcon.ShowCustomBalloon(balloon, PopupAnimation.Slide, 4000);
|
||||
}
|
||||
|
||||
private void btnHideStandardBalloon_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
MyNotifyIcon.HideBalloonTip();
|
||||
}
|
||||
|
||||
|
||||
private void btnShowStandardBalloon_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
string title = "WPF NotifyIcon";
|
||||
string text = "This is a standard balloon";
|
||||
|
||||
MyNotifyIcon.ShowBalloonTip(title, text, MyNotifyIcon.Icon);
|
||||
}
|
||||
|
||||
private void btnCloseCustomBalloon_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
MyNotifyIcon.CloseBalloon();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<Window
|
||||
x:Class="Samples.Tutorials.Commands.CommandWindow"
|
||||
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:local="clr-namespace:Samples.Tutorials.Commands"
|
||||
Height="300"
|
||||
Width="300"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d">
|
||||
<Grid>
|
||||
|
||||
<!-- declare the command as a local resource -->
|
||||
<Grid.Resources>
|
||||
<local:ShowMessageCommand
|
||||
x:Key="MessageCommand" />
|
||||
</Grid.Resources>
|
||||
|
||||
<!-- declare the NotifyIcon and configure commands with parameters -->
|
||||
<tb:TaskbarIcon
|
||||
x:Name="CustomCommandNotifyIcon"
|
||||
IconSource="/Icons/Error.ico"
|
||||
LeftClickCommand="{StaticResource MessageCommand}"
|
||||
LeftClickCommandParameter="Left mouse button was clicked"
|
||||
DoubleClickCommand="{StaticResource MessageCommand}"
|
||||
DoubleClickCommandParameter="Double click on NotifyIcon" />
|
||||
|
||||
<!-- declare the NotifyIcon and configure commands with targets -->
|
||||
<tb:TaskbarIcon
|
||||
x:Name="RoutedCommandNotifyIcon"
|
||||
IconSource="/Icons/Inactive.ico"
|
||||
LeftClickCommand="ApplicationCommands.Cut"
|
||||
LeftClickCommandTarget="{Binding ElementName=txtInput}"
|
||||
DoubleClickCommand="ApplicationCommands.Paste"
|
||||
DoubleClickCommandTarget="{Binding ElementName=txtInput}" />
|
||||
|
||||
|
||||
<TextBlock
|
||||
Margin="26,26,24,0"
|
||||
VerticalAlignment="Top"
|
||||
FontWeight="Bold"
|
||||
TextWrapping="Wrap">
|
||||
<Run
|
||||
Language="de-ch"
|
||||
Text="Left / Double clicks on red NotifyIcon executes simple custom commands." />
|
||||
</TextBlock>
|
||||
<TextBlock
|
||||
Margin="26,112,24,80"
|
||||
FontWeight="Bold"
|
||||
TextWrapping="Wrap">
|
||||
<Run Language="de-ch" Text="Left / Double clicks on grey NotifyIcon executes routed commands." />
|
||||
<LineBreak /><Run Language="de-ch" Text="Single click: Cuts selected text" /><LineBreak />
|
||||
<Run Language="de-ch" Text="Double click: Paste text from clipboard" />
|
||||
</TextBlock>
|
||||
<TextBox
|
||||
Margin="26,0,24,48"
|
||||
VerticalAlignment="Bottom"
|
||||
Height="22"
|
||||
Text="hello world"
|
||||
TextWrapping="Wrap"
|
||||
x:Name="txtInput" />
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,36 @@
|
||||
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.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace Samples.Tutorials.Commands
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for CommandWindow.xaml
|
||||
/// </summary>
|
||||
public partial class CommandWindow : Window
|
||||
{
|
||||
public CommandWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
|
||||
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
//clean up notifyicon (would otherwise stay open until application finishes)
|
||||
CustomCommandNotifyIcon.Dispose();
|
||||
RoutedCommandNotifyIcon.Dispose();
|
||||
|
||||
base.OnClosing(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Samples.Tutorials.Commands
|
||||
{
|
||||
/// <summary>
|
||||
/// A simple command that displays the command parameter as
|
||||
/// a dialog message.
|
||||
/// </summary>
|
||||
public class ShowMessageCommand : ICommand
|
||||
{
|
||||
public void Execute(object parameter)
|
||||
{
|
||||
MessageBox.Show(parameter.ToString());
|
||||
}
|
||||
|
||||
public bool CanExecute(object parameter)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public event EventHandler CanExecuteChanged;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,265 @@
|
||||
<Window
|
||||
x:Class="Samples.Tutorials.Events.EventVisualizerWindow"
|
||||
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="300"
|
||||
Width="300">
|
||||
<Window.Resources>
|
||||
<Storyboard
|
||||
x:Key="ShowMovement"
|
||||
AutoReverse="True">
|
||||
<DoubleAnimationUsingKeyFrames
|
||||
BeginTime="00:00:00"
|
||||
Storyboard.TargetName="MoveIndicator"
|
||||
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
|
||||
<SplineDoubleKeyFrame
|
||||
KeyTime="00:00:00"
|
||||
Value="1" />
|
||||
<SplineDoubleKeyFrame
|
||||
KeyTime="00:00:00.1000000"
|
||||
Value="1.2" />
|
||||
</DoubleAnimationUsingKeyFrames>
|
||||
<DoubleAnimationUsingKeyFrames
|
||||
BeginTime="00:00:00"
|
||||
Storyboard.TargetName="MoveIndicator"
|
||||
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
|
||||
<SplineDoubleKeyFrame
|
||||
KeyTime="00:00:00"
|
||||
Value="1" />
|
||||
<SplineDoubleKeyFrame
|
||||
KeyTime="00:00:00.1000000"
|
||||
Value="1.2" />
|
||||
</DoubleAnimationUsingKeyFrames>
|
||||
</Storyboard>
|
||||
<Storyboard
|
||||
x:Key="ShowMouseUp"
|
||||
AutoReverse="True">
|
||||
<DoubleAnimationUsingKeyFrames
|
||||
BeginTime="00:00:00"
|
||||
Storyboard.TargetName="LeftMouseIndicator"
|
||||
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
|
||||
<SplineDoubleKeyFrame
|
||||
KeyTime="00:00:00"
|
||||
Value="1" />
|
||||
<SplineDoubleKeyFrame
|
||||
KeyTime="00:00:00.1000000"
|
||||
Value="1.35" />
|
||||
</DoubleAnimationUsingKeyFrames>
|
||||
<DoubleAnimationUsingKeyFrames
|
||||
BeginTime="00:00:00"
|
||||
Storyboard.TargetName="LeftMouseIndicator"
|
||||
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
|
||||
<SplineDoubleKeyFrame
|
||||
KeyTime="00:00:00"
|
||||
Value="1" />
|
||||
<SplineDoubleKeyFrame
|
||||
KeyTime="00:00:00.1000000"
|
||||
Value="1.35" />
|
||||
</DoubleAnimationUsingKeyFrames>
|
||||
</Storyboard>
|
||||
<Storyboard
|
||||
x:Key="ShowToolTipOpened"
|
||||
AutoReverse="True">
|
||||
<DoubleAnimationUsingKeyFrames
|
||||
BeginTime="00:00:00"
|
||||
Storyboard.TargetName="ToolTipIndicator"
|
||||
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
|
||||
<SplineDoubleKeyFrame
|
||||
KeyTime="00:00:00"
|
||||
Value="1" />
|
||||
<SplineDoubleKeyFrame
|
||||
KeyTime="00:00:00.2000000"
|
||||
Value="1.4" />
|
||||
</DoubleAnimationUsingKeyFrames>
|
||||
<DoubleAnimationUsingKeyFrames
|
||||
BeginTime="00:00:00"
|
||||
Storyboard.TargetName="ToolTipIndicator"
|
||||
Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
|
||||
<SplineDoubleKeyFrame
|
||||
KeyTime="00:00:00"
|
||||
Value="1" />
|
||||
<SplineDoubleKeyFrame
|
||||
KeyTime="00:00:00.2000000"
|
||||
Value="1.4" />
|
||||
</DoubleAnimationUsingKeyFrames>
|
||||
</Storyboard>
|
||||
</Window.Resources>
|
||||
<Window.Triggers>
|
||||
<EventTrigger
|
||||
RoutedEvent="tb:TaskbarIcon.TrayMouseMove"
|
||||
SourceName="notifyIcon">
|
||||
<BeginStoryboard
|
||||
Storyboard="{StaticResource ShowMovement}" />
|
||||
</EventTrigger>
|
||||
<EventTrigger
|
||||
RoutedEvent="tb:TaskbarIcon.TrayLeftMouseUp"
|
||||
SourceName="notifyIcon">
|
||||
<BeginStoryboard
|
||||
Storyboard="{StaticResource ShowMouseUp}"
|
||||
x:Name="ShowMouseUp_BeginStoryboard" />
|
||||
</EventTrigger>
|
||||
<EventTrigger
|
||||
RoutedEvent="tb:TaskbarIcon.TrayToolTipOpen"
|
||||
SourceName="notifyIcon">
|
||||
<BeginStoryboard
|
||||
Storyboard="{StaticResource ShowToolTipOpened}"
|
||||
x:Name="ShowToolTipOpened_BeginStoryboard" />
|
||||
</EventTrigger>
|
||||
</Window.Triggers>
|
||||
<Grid>
|
||||
|
||||
<!-- the NotifyIcon does not need to be configured here - animations were set up in Blend -->
|
||||
<tb:TaskbarIcon
|
||||
x:Name="notifyIcon"
|
||||
ToolTipText="hello world"
|
||||
IconSource="/Icons/Error.ico" />
|
||||
|
||||
|
||||
<Ellipse
|
||||
HorizontalAlignment="Left"
|
||||
Margin="24,62,0,0"
|
||||
VerticalAlignment="Top"
|
||||
Width="19"
|
||||
Height="19"
|
||||
Stroke="#FF549D2D"
|
||||
x:Name="MoveIndicator"
|
||||
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.Fill>
|
||||
<LinearGradientBrush
|
||||
EndPoint="0.528,0.694"
|
||||
StartPoint="-0.056,-0.118">
|
||||
<GradientStop
|
||||
Color="#FFFFFFFF"
|
||||
Offset="0" />
|
||||
<GradientStop
|
||||
Color="#FF65A135"
|
||||
Offset="1" />
|
||||
</LinearGradientBrush>
|
||||
</Ellipse.Fill>
|
||||
</Ellipse>
|
||||
<Ellipse
|
||||
Stroke="#FF549D2D"
|
||||
HorizontalAlignment="Left"
|
||||
Margin="24,106,0,0"
|
||||
VerticalAlignment="Top"
|
||||
Width="19"
|
||||
Height="19"
|
||||
x:Name="LeftMouseIndicator"
|
||||
RenderTransformOrigin="0.5,0.5">
|
||||
<Ellipse.RenderTransform>
|
||||
<TransformGroup>
|
||||
<ScaleTransform />
|
||||
<SkewTransform
|
||||
AngleX="0"
|
||||
AngleY="0" />
|
||||
<RotateTransform
|
||||
Angle="0" />
|
||||
<TranslateTransform
|
||||
X="0"
|
||||
Y="0" />
|
||||
</TransformGroup>
|
||||
</Ellipse.RenderTransform>
|
||||
<Ellipse.Fill>
|
||||
<LinearGradientBrush
|
||||
EndPoint="0.528,0.694"
|
||||
StartPoint="-0.056,-0.118">
|
||||
<GradientStop
|
||||
Color="#FFFFFFFF"
|
||||
Offset="0" />
|
||||
<GradientStop
|
||||
Color="#FF65A135"
|
||||
Offset="1" />
|
||||
</LinearGradientBrush>
|
||||
</Ellipse.Fill>
|
||||
</Ellipse>
|
||||
<Ellipse
|
||||
Stroke="#FF549D2D"
|
||||
HorizontalAlignment="Left"
|
||||
Margin="24,0,0,94"
|
||||
Width="19"
|
||||
x:Name="ToolTipIndicator"
|
||||
RenderTransformOrigin="0.5,0.5"
|
||||
Height="19"
|
||||
VerticalAlignment="Bottom">
|
||||
<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.Fill>
|
||||
<LinearGradientBrush
|
||||
EndPoint="0.528,0.694"
|
||||
StartPoint="-0.056,-0.118">
|
||||
<GradientStop
|
||||
Color="#FFFFFFFF"
|
||||
Offset="0" />
|
||||
<GradientStop
|
||||
Color="#FF65A135"
|
||||
Offset="1" />
|
||||
</LinearGradientBrush>
|
||||
</Ellipse.Fill>
|
||||
</Ellipse>
|
||||
<TextBlock
|
||||
Margin="63,62,91,0"
|
||||
VerticalAlignment="Top"
|
||||
Height="19"
|
||||
TextWrapping="Wrap">
|
||||
<Run
|
||||
Language="de-ch"
|
||||
Text="TrayMouseMove Event" />
|
||||
</TextBlock>
|
||||
<TextBlock
|
||||
Margin="63,106,91,0"
|
||||
VerticalAlignment="Top"
|
||||
Height="19"
|
||||
TextWrapping="Wrap">
|
||||
<Run
|
||||
Language="de-ch"
|
||||
Text="TrayLeftMouseUp Event" />
|
||||
</TextBlock>
|
||||
<TextBlock
|
||||
Margin="63,0,91,94"
|
||||
TextWrapping="Wrap"
|
||||
VerticalAlignment="Bottom"
|
||||
Height="19">
|
||||
<Run
|
||||
Language="de-ch"
|
||||
Text="TrayToolTipOpen Event" />
|
||||
</TextBlock>
|
||||
<TextBlock
|
||||
Margin="10,10,10,0"
|
||||
VerticalAlignment="Top"
|
||||
Height="31"
|
||||
TextWrapping="Wrap"
|
||||
FontWeight="Bold">
|
||||
<Run Language="de-ch" Text="The green ellipses are animated based on routed events of the NotifyIcon" />
|
||||
</TextBlock>
|
||||
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,24 @@
|
||||
using System.Windows;
|
||||
|
||||
namespace Samples.Tutorials.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for EventVisualizerWindow.xaml
|
||||
/// </summary>
|
||||
public partial class EventVisualizerWindow : Window
|
||||
{
|
||||
public EventVisualizerWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
|
||||
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
//clean up notifyicon (would otherwise stay open until application finishes)
|
||||
notifyIcon.Dispose();
|
||||
|
||||
base.OnClosing(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<Window x:Class="Samples.Tutorials.DataBinding.DataBoundToolTipWindow"
|
||||
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="300"
|
||||
Width="500">
|
||||
<Grid>
|
||||
|
||||
<!-- the ToolTipText property is bound to the TextBox below -->
|
||||
<tb:TaskbarIcon x:Name="MyNotifyIcon1"
|
||||
IconSource="/Icons/Error.ico"
|
||||
ToolTipText="{Binding ElementName=txtToolTip, Path=Text}">
|
||||
|
||||
<!--
|
||||
The TextBlock bound to the ToolTipText property of the NotifyIcon
|
||||
The binding is implicit (using DataContext)
|
||||
-->
|
||||
<tb:TaskbarIcon.TrayToolTip>
|
||||
<Border Background="White"
|
||||
BorderBrush="Orange"
|
||||
BorderThickness="2"
|
||||
CornerRadius="4"
|
||||
Opacity="0.8"
|
||||
Width="160"
|
||||
Height="40">
|
||||
<TextBlock Text="{Binding Path=ToolTipText}"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center" />
|
||||
</Border>
|
||||
</tb:TaskbarIcon.TrayToolTip>
|
||||
|
||||
</tb:TaskbarIcon>
|
||||
|
||||
|
||||
<!-- This NotifyIcon has its DataContext set (just the string "WPF FTW") - implicit binding is no longer possible -->
|
||||
<tb:TaskbarIcon x:Name="MyNotifyIcon2"
|
||||
DataContext="WPF FTW "
|
||||
IconSource="/Icons/Inactive.ico"
|
||||
ToolTipText="{Binding ElementName=txtToolTip, Path=Text}">
|
||||
|
||||
<tb:TaskbarIcon.TrayToolTip>
|
||||
|
||||
<!--
|
||||
Important: The attached property is assigned to the border, but derived by all controls.
|
||||
The NotifyIcon does not touch the underlying controls.
|
||||
-->
|
||||
<Border Background="White"
|
||||
BorderBrush="Orange"
|
||||
BorderThickness="2"
|
||||
CornerRadius="4"
|
||||
Opacity="0.8"
|
||||
Width="160"
|
||||
Height="40">
|
||||
<!-- Implicitly access the DataContext (which is a string this time)-->
|
||||
<TextBlock Text="{Binding}">
|
||||
<!-- Explicitly access the NotifyIcon, as it is an attached property -->
|
||||
<TextBlock Text="{Binding RelativeSource={RelativeSource Self},
|
||||
Path=(tb:TaskbarIcon.ParentTaskbarIcon).ToolTipText}"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center" />
|
||||
</TextBlock>
|
||||
</Border>
|
||||
</tb:TaskbarIcon.TrayToolTip>
|
||||
|
||||
</tb:TaskbarIcon>
|
||||
|
||||
|
||||
<TextBlock Margin="26,26,24,0"
|
||||
VerticalAlignment="Top"
|
||||
TextWrapping="Wrap"
|
||||
FontWeight="Bold">
|
||||
<Run Text="This sample shows data bound ToolTips in two flavors" /><LineBreak /><Run Text="" />
|
||||
<LineBreak /><Run Text="- implicit binding via DataContext" /><LineBreak />
|
||||
<Run Text="- explicit binding via ParentTaskbarIcon (attached property)" /><LineBreak /><Run Text="" />
|
||||
<LineBreak /><Run Text="Move over NotifyIcons (grey / red) to show data bound ToolTip" />
|
||||
</TextBlock>
|
||||
<TextBox Margin="26,0,24,10"
|
||||
Text="hello world"
|
||||
TextWrapping="Wrap"
|
||||
x:Name="txtToolTip"
|
||||
Height="25"
|
||||
VerticalAlignment="Bottom" />
|
||||
<TextBlock Margin="26,0,125,45"
|
||||
VerticalAlignment="Bottom"
|
||||
Height="26"
|
||||
TextWrapping="Wrap">
|
||||
<Run Text="ToolTipText:" />
|
||||
</TextBlock>
|
||||
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,25 @@
|
||||
using System.Windows;
|
||||
|
||||
namespace Samples.Tutorials.DataBinding
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for DataBoundToolTipWindow.xaml
|
||||
/// </summary>
|
||||
public partial class DataBoundToolTipWindow : Window
|
||||
{
|
||||
public DataBoundToolTipWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
|
||||
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
//clean up notifyicon (would otherwise stay open until application finishes)
|
||||
MyNotifyIcon1.Dispose();
|
||||
MyNotifyIcon2.Dispose();
|
||||
|
||||
base.OnClosing(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
@@ -0,0 +1,37 @@
|
||||
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
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"
|
||||
mc:Ignorable="d"
|
||||
x:Class="Samples.Tutorials.MvvmSample.ClockPopup"
|
||||
x:Name="UserControl"
|
||||
Height="141"
|
||||
Width="304">
|
||||
<UserControl.Background>
|
||||
<LinearGradientBrush EndPoint="0.5,1"
|
||||
StartPoint="0.5,0">
|
||||
<GradientStop Color="#FFA8A8A8"
|
||||
Offset="0" />
|
||||
<GradientStop Color="White"
|
||||
Offset="1" />
|
||||
</LinearGradientBrush>
|
||||
</UserControl.Background>
|
||||
|
||||
<Grid x:Name="LayoutRoot">
|
||||
<Rectangle Stroke="#FF727272"/>
|
||||
<Image Source="Clock.png"
|
||||
Stretch="Fill"
|
||||
Height="128"
|
||||
VerticalAlignment="Top"
|
||||
HorizontalAlignment="Left"
|
||||
Width="128"
|
||||
Margin="10,10,0,0" />
|
||||
<TextBlock HorizontalAlignment="Left"
|
||||
Margin="143,0,0,0"
|
||||
TextWrapping="Wrap"
|
||||
Text="{Binding Timestamp}"
|
||||
VerticalAlignment="Center"
|
||||
FontSize="40"
|
||||
Foreground="#F2346172" />
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,15 @@
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Samples.Tutorials.MvvmSample
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for ClockPopup.xaml
|
||||
/// </summary>
|
||||
public partial class ClockPopup : UserControl
|
||||
{
|
||||
public ClockPopup()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace Samples.Tutorials.MvvmSample
|
||||
{
|
||||
public class MvvmSampleViewModel : INotifyPropertyChanged
|
||||
{
|
||||
private DispatcherTimer timer;
|
||||
|
||||
public string Timestamp
|
||||
{
|
||||
get { return DateTime.Now.ToLongTimeString(); }
|
||||
}
|
||||
|
||||
|
||||
public MvvmSampleViewModel()
|
||||
{
|
||||
timer = new DispatcherTimer(TimeSpan.FromSeconds(1), DispatcherPriority.Normal, OnTimerTick, Application.Current.Dispatcher);
|
||||
}
|
||||
|
||||
private void OnTimerTick(object sender, EventArgs e)
|
||||
{
|
||||
//fire a property change event for the timestamp
|
||||
Application.Current.Dispatcher.BeginInvoke(new Action(() => OnPropertyChanged("Timestamp")));
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
protected virtual void OnPropertyChanged(string propertyName)
|
||||
{
|
||||
PropertyChangedEventHandler handler = PropertyChanged;
|
||||
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<Window x:Class="Samples.Tutorials.MvvmSample.MvvmSampleWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:Samples.Tutorials.MvvmSample"
|
||||
xmlns:tb="http://www.hardcodet.net/taskbar"
|
||||
Title="MvvmSampleWindow"
|
||||
Height="300"
|
||||
Width="300">
|
||||
<Window.DataContext>
|
||||
<local:MvvmSampleViewModel />
|
||||
</Window.DataContext>
|
||||
<Grid>
|
||||
|
||||
|
||||
<!--
|
||||
the NotifyIcon automatically derives the DataContext of it's
|
||||
declaring view. Alternatively, you could just assign it manually
|
||||
-->
|
||||
<tb:TaskbarIcon IconSource="/Icons/Inactive.ico"
|
||||
ToolTipText="{Binding Timestamp}">
|
||||
<tb:TaskbarIcon.TrayPopup >
|
||||
<!-- the popup, here a custom user control, will also get the DataContext of the NotifyIcon -->
|
||||
<local:ClockPopup Opacity="0.8" />
|
||||
</tb:TaskbarIcon.TrayPopup>
|
||||
</tb:TaskbarIcon>
|
||||
|
||||
|
||||
|
||||
<TextBlock TextWrapping="Wrap"
|
||||
Text="MVVM is quite simple - content of the NotifyIcon derive its DataContext. Sample: Hover over the icon in order to see the bound ToolTipText. Click for a richer Popup that is bound to the same property."
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Top"
|
||||
Margin="10,10,10,0" />
|
||||
|
||||
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,15 @@
|
||||
using System.Windows;
|
||||
|
||||
namespace Samples.Tutorials.MvvmSample
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MvvmSampleWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MvvmSampleWindow : Window
|
||||
{
|
||||
public MvvmSampleWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user