Added .NET 5.0 and restructured the repository. (#47)

This commit is contained in:
Robin Krom
2020-11-22 22:04:27 +01:00
committed by GitHub
parent de6a2b2e25
commit 9e86ac77d3
100 changed files with 201 additions and 184 deletions

View File

@@ -0,0 +1,21 @@
<Application x:Class="NotifyIconWpf.Sample.Windowless.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>

View File

@@ -0,0 +1,27 @@
using System.Windows;
using Hardcodet.Wpf.TaskbarNotification;
namespace NotifyIconWpf.Sample.Windowless
{
/// <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);
}
}
}

View File

@@ -0,0 +1,30 @@
using System;
using System.Windows.Input;
namespace NotifyIconWpf.Sample.Windowless
{
/// <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; }
}
}
}

View File

@@ -0,0 +1,8 @@
<Window x:Class="NotifyIconWpf.Sample.Windowless.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>

View File

@@ -0,0 +1,15 @@
using System.Windows;
namespace NotifyIconWpf.Sample.Windowless
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
}

View 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:NotifyIconWpf.Sample.Windowless">
<!-- 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>

View File

@@ -0,0 +1,59 @@
using System.Windows;
using System.Windows.Input;
namespace NotifyIconWpf.Sample.Windowless
{
/// <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()};
}
}
}
}

View File

@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFrameworks>net45;net472;netcoreapp3.1;net5.0-windows</TargetFrameworks>
<GenerateResourceUsePreserializedResources>true</GenerateResourceUsePreserializedResources>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\NotifyIconWpf\NotifyIconWpf.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'net45'">
<PackageReference Include="System.Resources.Extensions" Version="5.0.0" PrivateAssets="All"/>
</ItemGroup>
<ItemGroup Condition="$(TargetFramework.StartsWith('net4'))">
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Xaml" />
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<Compile DependentUpon="%(Filename)" SubType="Code" Update="**\obj\**\*.g$(DefaultLanguageSourceExtension)" />
<Compile DependentUpon="%(Filename)" SubType="Designer" Update="**\*.xaml$(DefaultLanguageSourceExtension)" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,26 @@
using System.Runtime.InteropServices;
using System.Windows;
// 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)
)]

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<System.Windows.Forms.ApplicationConfigurationSection>
<add key="DpiAwareness" value="PerMonitorV2" />
</System.Windows.Forms.ApplicationConfigurationSection>
</configuration>

View File

@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<!-- Make sure windows Vista and above treat Greenshot as "DPI Aware" See: http://msdn.microsoft.com/en-us/library/ms633543.aspx -->
<asmv3:application>
<asmv3:windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">True/PM</dpiAware>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2,PerMonitor</dpiAwareness>
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
<gdiScaling xmlns="http://schemas.microsoft.com/SMI/2017/WindowsSettings">false</gdiScaling>
</asmv3:windowsSettings>
</asmv3:application>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
<maxversiontested Id="10.0.18363.0"/>
<!-- Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />
<!--Windows 8 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />
<!-- Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />
</application>
</compatibility>
<!-- Set UAC level to "asInvoker" and disable registry virtualization -->
<asmv2:trustInfo>
<asmv2:security>
<asmv3:requestedPrivileges>
<!--
The presence of the "requestedExecutionLevel" node will disable
file and registry virtualization on Vista. See:
http://msdn.microsoft.com/en-us/library/aa965884%28v=vs.85%29.aspx
Use the "level" attribute to specify the User Account Control level:
asInvoker = Never prompt for elevation
requireAdministrator = Always prompt for elevation
highestAvailable = Prompt for elevation when started by administrator,
but do not prompt for administrator password when started by
standard user.
-->
<asmv3:requestedExecutionLevel level="asInvoker" />
</asmv3:requestedPrivileges>
</asmv2:security>
</asmv2:trustInfo>
</assembly>