IT\pgermain 7 月之前
父節點
當前提交
5bf08ec0a9

+ 9 - 0
App.xaml

@@ -0,0 +1,9 @@
+<Application x:Class="CountDown.App"
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:local="clr-namespace:CountDown"
+             StartupUri="MainWindow.xaml">
+    <Application.Resources>
+         
+    </Application.Resources>
+</Application>

+ 20 - 0
App.xaml.cs

@@ -0,0 +1,20 @@
+using System.Windows;
+using Microsoft.Extensions.Configuration;
+
+namespace CountDown;
+
+/// <summary>
+/// Interaction logic for App.xaml
+/// </summary>
+public partial class App : Application
+{
+    public static IConfiguration? Config { get; private set; }
+
+    public App()
+    {
+        Config = new ConfigurationBuilder()
+            .AddJsonFile("appsettings.json")
+            .Build();
+    }
+}
+

+ 10 - 0
AssemblyInfo.cs

@@ -0,0 +1,10 @@
+using System.Windows;
+
+[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)
+)]

+ 25 - 0
CountDown.csproj

@@ -0,0 +1,25 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>WinExe</OutputType>
+    <TargetFramework>net8.0-windows7.0</TargetFramework>
+    <Nullable>enable</Nullable>
+    <ImplicitUsings>enable</ImplicitUsings>
+    <UseWPF>true</UseWPF>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
+  </ItemGroup>
+
+
+  <ItemGroup>
+    <None Update="appsettings.json">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+    <None Update="background.png">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
+  </ItemGroup>
+
+</Project>

+ 6 - 0
CountDown.csproj.user

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <_LastSelectedProfileId>C:\Users\pgermain\source\repos\CountDown\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
+  </PropertyGroup>
+</Project>

+ 24 - 0
CountDown.sln

@@ -0,0 +1,24 @@
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.5.2.0
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CountDown", "CountDown.csproj", "{E4D229D1-8488-C731-4FA4-2EF56E9DCA26}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{E4D229D1-8488-C731-4FA4-2EF56E9DCA26}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{E4D229D1-8488-C731-4FA4-2EF56E9DCA26}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{E4D229D1-8488-C731-4FA4-2EF56E9DCA26}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{E4D229D1-8488-C731-4FA4-2EF56E9DCA26}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {0A9A918B-EA48-4100-8DE8-903FA416C833}
+	EndGlobalSection
+EndGlobal

+ 15 - 0
MainWindow.xaml

@@ -0,0 +1,15 @@
+<Window x:Class="CountDown.MainWindow"
+        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"
+        xmlns:local="clr-namespace:CountDown"
+        mc:Ignorable="d"
+        Title="Bientôt la retraite !!!" Height="180" Width="180"
+        Background="Transparent"
+        WindowStyle="ToolWindow"
+        ShowInTaskbar="false">
+    <Grid>
+        <TextBlock Text="{Binding Counter,StringFormat={}{0:dd\\jhh\\hmm\\mss\\'}}" HorizontalAlignment="Center" VerticalAlignment="Bottom" FontSize="28" Foreground="White" FontFamily="Agency FB"/>
+    </Grid>
+</Window>

+ 83 - 0
MainWindow.xaml.cs

@@ -0,0 +1,83 @@
+using System;
+using System.Diagnostics.Eventing.Reader;
+using System.Globalization;
+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;
+using System.Windows.Threading;
+using Microsoft.Extensions.Configuration;
+
+
+namespace CountDown;
+
+/// <summary>
+/// Interaction logic for MainWindow.xaml
+/// </summary>
+public partial class MainWindow : Window
+{
+
+    public DateTime EventDate { get; set; }
+    private DispatcherTimer _timer;
+    readonly CultureInfo _enUS = new ("en-US");
+    public TimeSpan Counter
+    {
+        get { return (TimeSpan)GetValue(CounterProperty); }
+        set { SetValue(CounterProperty, value); }
+    }
+
+    public static readonly DependencyProperty CounterProperty =
+        DependencyProperty.Register(nameof(Counter), typeof(TimeSpan), typeof(MainWindow), new PropertyMetadata(new TimeSpan(0, 0, 0)));
+
+
+    public MainWindow()
+    {
+        InitializeComponent();
+
+        DataContext = this;
+
+       
+        
+        var dateString = App.Config?.GetChildren().FirstOrDefault(c => c.Key == "EventDate")?.Value ?? "2025-06-30 23:59:59";
+        if (DateTime.TryParseExact(dateString, "yyyy-MM-dd HH:mm:s", _enUS,
+                                 DateTimeStyles.None, out DateTime dateValue))
+        {
+            EventDate = dateValue;
+        }
+        else
+        {
+            EventDate = new DateTime(2025, 06, 30, 23, 59, 59, DateTimeKind.Local);
+        }
+
+        Left = System.Windows.SystemParameters.PrimaryScreenWidth - Width - 20;
+        Top = System.Windows.SystemParameters.PrimaryScreenHeight - Height - 100;
+        Topmost = true;
+
+        BitmapImage image = new (new Uri("./background.png", UriKind.Relative));
+        ImageBrush fond = new (image);
+        this.Background = fond;
+
+        _timer = new();
+        _timer.Interval = new TimeSpan(0, 0, 1);
+        _timer.Tick += TimerTicked;
+        _timer.Start();
+    }
+
+    private void SetTime()
+    {
+        Counter = EventDate - DateTime.Now;
+    }
+
+    private void TimerTicked(object? sender, EventArgs e)
+    {
+        SetTime();
+    }
+
+
+}

+ 11 - 0
Properties/PublishProfiles/FolderProfile.pubxml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- https://go.microsoft.com/fwlink/?LinkID=208121. -->
+<Project>
+  <PropertyGroup>
+    <Configuration>Release</Configuration>
+    <Platform>Any CPU</Platform>
+    <PublishDir>bin\Release\net9.0-windows\publish\</PublishDir>
+    <PublishProtocol>FileSystem</PublishProtocol>
+    <_TargetId>Folder</_TargetId>
+  </PropertyGroup>
+</Project>

+ 8 - 0
Properties/PublishProfiles/FolderProfile.pubxml.user

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- https://go.microsoft.com/fwlink/?LinkID=208121. -->
+<Project>
+  <PropertyGroup>
+    <History>True|2025-03-14T14:39:40.2134821Z||;True|2025-03-14T15:35:53.3070919+01:00||;True|2025-03-14T15:16:13.5969743+01:00||;True|2025-03-14T15:09:16.2949789+01:00||;True|2025-03-10T11:19:05.3590708+01:00||;True|2025-03-10T11:02:03.7335405+01:00||;True|2025-03-10T10:56:44.0573243+01:00||;True|2025-03-10T10:54:58.9740819+01:00||;True|2025-03-10T10:16:19.7655552+01:00||;True|2025-03-10T10:13:41.4950851+01:00||;False|2025-03-10T10:13:09.0342838+01:00||;True|2025-03-10T10:11:34.8739688+01:00||;</History>
+    <LastFailureDetails />
+  </PropertyGroup>
+</Project>

+ 3 - 0
appsettings.json

@@ -0,0 +1,3 @@
+{
+  "EventDate" : "2025-06-30 17:30:00"  
+}

二進制
background.png