mirror of
https://github.com/ckaczor/wpf-notifyicon.git
synced 2026-01-14 01:25:45 -05:00
ADD Sample for windowless application.
NTFY-25 git-svn-id: https://svn.evolvesoftware.ch/repos/evolve.net/WPF/NotifyIcon@203 9f600761-6f11-4665-b6dc-0185e9171623
This commit is contained in:
21
Source/Windowless Sample/App.xaml
Normal file
21
Source/Windowless Sample/App.xaml
Normal file
@@ -0,0 +1,21 @@
|
||||
<Application x:Class="Windowless_Sample.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
ShutdownMode="OnExplicitShutdown">
|
||||
<Application.Resources>
|
||||
|
||||
<!--
|
||||
Note that this application does not have a StartupUri declared, so no Window is automatically loaded.
|
||||
Also, the ShutdownMode was set to explicit, so we have to close the application programmatically
|
||||
-->
|
||||
|
||||
|
||||
<!-- merge NotifyIcon and related stuff into the application -->
|
||||
<ResourceDictionary>
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="NotifyIconResources.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
</ResourceDictionary>
|
||||
|
||||
</Application.Resources>
|
||||
</Application>
|
||||
27
Source/Windowless Sample/App.xaml.cs
Normal file
27
Source/Windowless Sample/App.xaml.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System.Windows;
|
||||
using Hardcodet.Wpf.TaskbarNotification;
|
||||
|
||||
namespace Windowless_Sample
|
||||
{
|
||||
/// <summary>
|
||||
/// Simple application. Check the XAML for comments.
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
private TaskbarIcon notifyIcon;
|
||||
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
base.OnStartup(e);
|
||||
|
||||
//create the notifyicon (it's a resource declared in NotifyIconResources.xaml
|
||||
notifyIcon = (TaskbarIcon) FindResource("NotifyIcon");
|
||||
}
|
||||
|
||||
protected override void OnExit(ExitEventArgs e)
|
||||
{
|
||||
notifyIcon.Dispose(); //the icon would clean up automatically, but this is cleaner
|
||||
base.OnExit(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
8
Source/Windowless Sample/MainWindow.xaml
Normal file
8
Source/Windowless Sample/MainWindow.xaml
Normal file
@@ -0,0 +1,8 @@
|
||||
<Window x:Class="Windowless_Sample.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">
|
||||
<Grid>
|
||||
<TextBlock Text="Have a look at App.xaml and App.xaml.cs to see how things are working" />
|
||||
</Grid>
|
||||
</Window>
|
||||
28
Source/Windowless Sample/MainWindow.xaml.cs
Normal file
28
Source/Windowless Sample/MainWindow.xaml.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
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 Windowless_Sample
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
32
Source/Windowless Sample/NotifyIconResources.xaml
Normal file
32
Source/Windowless Sample/NotifyIconResources.xaml
Normal file
@@ -0,0 +1,32 @@
|
||||
<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"
|
||||
xmlns:local="clr-namespace:Windowless_Sample">
|
||||
|
||||
<!-- The taskbar context menu - the first row is a dummy to show off simple data binding -->
|
||||
<!--
|
||||
The "shared" directive is needed if we reopen the sample window a few times - WPF will otherwise
|
||||
reuse the same context menu (which is a resource) again (which will have its DataContext set to the old TaskbarIcon)
|
||||
-->
|
||||
<ContextMenu x:Shared="false" x:Key="SysTrayMenu">
|
||||
<MenuItem Header="Show Window" Command="{Binding ShowWindowCommand}" />
|
||||
<MenuItem Header="Hide Window" Command="{Binding HideWindowCommand}" />
|
||||
<Separator />
|
||||
<MenuItem Header="Exit" Command="{Binding ExitApplicationCommand}" />
|
||||
</ContextMenu>
|
||||
|
||||
|
||||
<!-- the application's NotifyIcon - started from App.xaml.cs. Declares its own view model. -->
|
||||
<tb:TaskbarIcon x:Key="NotifyIcon"
|
||||
IconSource="/Red.ico"
|
||||
ToolTipText="Double-click for window, right-click for menu"
|
||||
DoubleClickCommand="{Binding ShowWindowCommand}"
|
||||
ContextMenu="{StaticResource SysTrayMenu}">
|
||||
|
||||
<!-- self-assign a data context (could also be done programmatically) -->
|
||||
<tb:TaskbarIcon.DataContext>
|
||||
<local:NotifyIconViewModel />
|
||||
</tb:TaskbarIcon.DataContext>
|
||||
</tb:TaskbarIcon>
|
||||
|
||||
</ResourceDictionary>
|
||||
86
Source/Windowless Sample/NotifyIconViewModel.cs
Normal file
86
Source/Windowless Sample/NotifyIconViewModel.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Windowless_Sample
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides bindable properties and commands for the NotifyIcon. In this sample, the
|
||||
/// view model is assigned to the NotifyIcon in XAML. Alternatively, the startup routing
|
||||
/// in App.xaml.cs could have created this view model, and assigned it to the NotifyIcon.
|
||||
/// </summary>
|
||||
public class NotifyIconViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Shows a window, if none is already open.
|
||||
/// </summary>
|
||||
public ICommand ShowWindowCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return new DelegateCommand
|
||||
{
|
||||
CanExecuteFunc = () => Application.Current.MainWindow == null,
|
||||
CommandAction = () =>
|
||||
{
|
||||
Application.Current.MainWindow = new MainWindow();
|
||||
Application.Current.MainWindow.Show();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hides the main window. This command is only enabled if a window is open.
|
||||
/// </summary>
|
||||
public ICommand HideWindowCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return new DelegateCommand
|
||||
{
|
||||
CommandAction = () => Application.Current.MainWindow.Close(),
|
||||
CanExecuteFunc = () => Application.Current.MainWindow != null
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Shuts down the application.
|
||||
/// </summary>
|
||||
public ICommand ExitApplicationCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
return new DelegateCommand {CommandAction = () => Application.Current.Shutdown()};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Simplistic delegate command for the demo.
|
||||
/// </summary>
|
||||
public class DelegateCommand : ICommand
|
||||
{
|
||||
public Action CommandAction { get; set; }
|
||||
public Func<bool> CanExecuteFunc { get; set; }
|
||||
|
||||
public void Execute(object parameter)
|
||||
{
|
||||
CommandAction();
|
||||
}
|
||||
|
||||
public bool CanExecute(object parameter)
|
||||
{
|
||||
return CanExecuteFunc == null || CanExecuteFunc();
|
||||
}
|
||||
|
||||
public event EventHandler CanExecuteChanged
|
||||
{
|
||||
add { CommandManager.RequerySuggested += value; }
|
||||
remove { CommandManager.RequerySuggested -= value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
55
Source/Windowless Sample/Properties/AssemblyInfo.cs
Normal file
55
Source/Windowless Sample/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System.Reflection;
|
||||
using System.Resources;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Windowless Sample")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Windowless Sample")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2013")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
//In order to begin building localizable applications, set
|
||||
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
|
||||
//inside a <PropertyGroup>. For example, if you are using US english
|
||||
//in your source files, set the <UICulture> to en-US. Then uncomment
|
||||
//the NeutralResourceLanguage attribute below. Update the "en-US" in
|
||||
//the line below to match the UICulture setting in the project file.
|
||||
|
||||
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
|
||||
|
||||
|
||||
[assembly: ThemeInfo(
|
||||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
|
||||
//(used if a resource is not found in the page,
|
||||
// or application resource dictionaries)
|
||||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
|
||||
//(used if a resource is not found in the page,
|
||||
// app, or any theme specific resource dictionaries)
|
||||
)]
|
||||
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
BIN
Source/Windowless Sample/Red.ico
Normal file
BIN
Source/Windowless Sample/Red.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
98
Source/Windowless Sample/Windowless Sample.csproj
Normal file
98
Source/Windowless Sample/Windowless Sample.csproj
Normal file
@@ -0,0 +1,98 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{964EBFBE-A600-49B2-BDD8-422B46F1D544}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Windowless_Sample</RootNamespace>
|
||||
<AssemblyName>Windowless Sample</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Xaml">
|
||||
<RequiredTargetFramework>4.0</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="WindowsBase" />
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ApplicationDefinition Include="App.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
<Page Include="MainWindow.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Compile Include="App.xaml.cs">
|
||||
<DependentUpon>App.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="MainWindow.xaml.cs">
|
||||
<DependentUpon>MainWindow.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Page Include="NotifyIconResources.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="NotifyIconViewModel.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<AppDesigner Include="Properties\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\NotifyIconWpf\NotifyIconWpf.csproj">
|
||||
<Project>{7AC63864-7638-41C4-969C-D3197EF2BED9}</Project>
|
||||
<Name>NotifyIconWpf</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Resource Include="Red.ico" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
Reference in New Issue
Block a user