migration
All checks were successful
Build and publish package / Build (push) Successful in 32s
Build and publish package / Determine version (push) Successful in 18s
Build and publish package / Pack (push) Successful in 36s
Build and publish package / Publish (push) Successful in 12s

This commit is contained in:
2026-02-15 19:00:05 +01:00
Unverified
parent 4196372923
commit 57debe2086
12 changed files with 968 additions and 2 deletions

View File

@@ -0,0 +1,56 @@
# SimpleToolkit.UI.WinUI.Controls
### Set of helpers, class extensions, UI controls used in my other C# projects
SimpleToolkit is package of useful classes, helpers, extensions and UI controls, I use in my C# projects. UI.WinUI.Controls subpackage contains custom UI controls for WinUI applications.
---
## NuGet registry status
| Subpackage | Status |
|--------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **SimpleToolkit.UI.WinUI.Controls** | [![NuGet version (SimpleToolkit.UI.WinUI.Controls)](https://img.shields.io/nuget/v/SimpleToolkit.UI.WinUI.Controls.svg?style=flat-square)](https://www.nuget.org/packages/SimpleToolkit.UI.WinUI.Controls/) |
| SimpleToolkit.Extensions | [![NuGet version (SimpleToolkit.Extensions)](https://img.shields.io/nuget/v/SimpleToolkit.Extensions.svg?style=flat-square)](https://www.nuget.org/packages/SimpleToolkit.Extensions/) |
| SimpleToolkit.Attributes | [![NuGet version (SimpleToolkit.Attributes)](https://img.shields.io/nuget/v/SimpleToolkit.Attributes.svg?style=flat-square)](https://www.nuget.org/packages/SimpleToolkit.Attributes/) |
| SimpleToolkit.MVVM | [![NuGet version (SimpleToolkit.MVVM)](https://img.shields.io/nuget/v/SimpleToolkit.MVVM.svg?style=flat-square)](https://www.nuget.org/packages/SimpleToolkit.MVVM/) |
| SimpleToolkit.UI.Models | [![NuGet version (SimpleToolkit.UI.Models)](https://img.shields.io/nuget/v/SimpleToolkit.UI.Models.svg?style=flat-square)](https://www.nuget.org/packages/SimpleToolkit.UI.Models/) |
| SimpleToolkit.UI.WinUI.Behaviors | [![NuGet version (SimpleToolkit.UI.WinUI.Behaviors)](https://img.shields.io/nuget/v/SimpleToolkit.UI.WinUI.Behaviors.svg?style=flat-square)](https://www.nuget.org/packages/SimpleToolkit.UI.WinUI.Behaviors/) |
| SimpleToolkit.UI.WinUI.Converters | [![NuGet version (SimpleToolkit.UI.WinUI.Converters)](https://img.shields.io/nuget/v/SimpleToolkit.UI.WinUI.Converters.svg?style=flat-square)](https://www.nuget.org/packages/SimpleToolkit.UI.WinUI.Converters/) |
| SimpleToolkit.UI.WinUI.Helpers | [![NuGet version (SimpleToolkit.UI.WinUI.Helpers)](https://img.shields.io/nuget/v/SimpleToolkit.UI.WinUI.Helpers.svg?style=flat-square)](https://www.nuget.org/packages/SimpleToolkit.UI.WinUI.Helpers/) |
## Features
- **TimeSpanControl** - allows to select TimeSpan
## Dependencies
Dependencies should be installed automatically with this package
- Microsoft.WindowsAppSDK 1.4.240211001
## Installation and usage
You can download package from official NuGet registry or .nupkg file itself from Releases tab.
**CLI:**
```
dotnet add package SimpleToolkit.UI.WinUI.Controls
```
**Package reference in .csproj file:**
```
<PackageReference Include="SimpleToolkit.UI.WinUI.Controls" Version="<version>" />
```
## Attribution and contribution
This project is open source on MIT License, so you can just copy and upload again to your repository. But according to the license, you must include information about the original author. You can find license [here](https://repos.mateuszskoczek.com/SimpleToolkit/SimpleToolkit.UI.WinUI.Controls/src/branch/main/LICENSE).
However, the preferred way to contribute would be to propose improvements in a pull request, through issues, or through other means of communication.
**Other sources:**
- Icon by [Icons8](icons8.com)

View File

@@ -0,0 +1,39 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RootNamespace>SimpleToolkit.UI.WinUI.Controls</RootNamespace>
<RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
<UseWinUI>true</UseWinUI>
<UseRidGraph>true</UseRidGraph>
<PackageReadmeFile>README.md</PackageReadmeFile>
<EnableCoreMrtTooling Condition=" '$(BuildingInsideVisualStudio)' != 'true' ">false</EnableCoreMrtTooling>
<Nullable>enable</Nullable>
<Title>SimpleToolkit.UI.WinUI.Controls</Title>
<Authors>Mateusz Skoczek</Authors>
<Copyright>Mateusz Skoczek</Copyright>
<PackageProjectUrl>https://repos.mateuszskoczek.com/SimpleToolkit/</PackageProjectUrl>
<PackageLicenseUrl>https://repos.mateuszskoczek.com/SimpleToolkit/SimpleToolkit.UI.WinUI.Controls/src/branch/main/LICENSE</PackageLicenseUrl>
<PackageIcon>icon.png</PackageIcon>
<RepositoryUrl>https://repos.mateuszskoczek.com/SimpleToolkit/SimpleToolkit.UI.WinUI.Controls</RepositoryUrl>
<Description>Set of helpers, class extensions, UI controls used in my other C# projects - Custom UI controls for WinUI applications</Description>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
</PropertyGroup>
<ItemGroup>
<None Update="icon.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
<None Update="README.md">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.4.240211001" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,177 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SimpleToolkit.UI.WinUI.Controls
{
public class TimeSpanControl : Grid
{
#region FIELDS
protected NumberBox _hours;
protected NumberBox _minutes;
protected NumberBox _seconds;
#endregion
#region PROPERTIES
public TimeSpan Value
{
get => (TimeSpan)GetValue(ValueProperty);
set => SetValue(ValueProperty, value);
}
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(TimeSpan), typeof(TimeSpanControl), new PropertyMetadata(TimeSpan.Zero, new PropertyChangedCallback(ValuePropertyChanged)));
public TimeSpan Maximum
{
get => (TimeSpan)GetValue(MaximumProperty);
set => SetValue(MaximumProperty, value);
}
public static readonly DependencyProperty MaximumProperty = DependencyProperty.Register("Maximum", typeof(TimeSpan), typeof(TimeSpanControl), new PropertyMetadata(TimeSpan.MaxValue, new PropertyChangedCallback(RangePropertyChanged)));
public TimeSpan Minimum
{
get => (TimeSpan)GetValue(MinimumProperty);
set => SetValue(MinimumProperty, value);
}
public static readonly DependencyProperty MinimumProperty = DependencyProperty.Register("Minimum", typeof(TimeSpan), typeof(TimeSpanControl), new PropertyMetadata(TimeSpan.Zero, new PropertyChangedCallback(RangePropertyChanged)));
#endregion
#region CONSTRUCTORS
public TimeSpanControl()
{
this.Build();
base.Loaded += this.OnLoaded;
}
#endregion
#region PRIVATE METHODS
protected void Build()
{
this.ColumnSpacing = 4;
this.ColumnDefinitions.Add(new ColumnDefinition());
this.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
this.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
this.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
this.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
_hours = new NumberBox
{
SpinButtonPlacementMode = NumberBoxSpinButtonPlacementMode.Compact,
Minimum = 0,
Value = 0,
};
_hours.ValueChanged += ValueChanged;
Children.Add(_hours);
SetColumn(_hours, 0);
TextBlock sep1 = new TextBlock
{
VerticalAlignment = VerticalAlignment.Center,
Padding = new Thickness(0, 0, 0, 5),
Text = ":"
};
Children.Add(sep1);
SetColumn(sep1, 1);
_minutes = new NumberBox
{
SpinButtonPlacementMode = NumberBoxSpinButtonPlacementMode.Compact,
Minimum = 0,
Maximum = 59,
Value = 0,
};
_minutes.ValueChanged += ValueChanged;
Children.Add(_minutes);
SetColumn(_minutes, 2);
TextBlock sep2 = new TextBlock
{
VerticalAlignment = VerticalAlignment.Center,
Padding = new Thickness(0, 0, 0, 5),
Text = ":"
};
Children.Add(sep2);
SetColumn(sep2, 3);
_seconds = new NumberBox
{
SpinButtonPlacementMode = NumberBoxSpinButtonPlacementMode.Compact,
Minimum = 0,
Maximum = 59,
Value = 0,
};
_seconds.ValueChanged += ValueChanged;
Children.Add(_seconds);
SetColumn(_seconds, 4);
}
protected void UpdateOnChanges()
{
if (this.IsLoaded)
{
TimeSpan hoursTimeSpan = TimeSpan.FromHours(_hours.Value);
TimeSpan minutesTimeSpan = TimeSpan.FromMinutes(_minutes.Value);
TimeSpan secondsTimeSpan = TimeSpan.FromSeconds(_seconds.Value);
TimeSpan value = secondsTimeSpan + minutesTimeSpan + hoursTimeSpan;
if (value >= Maximum)
{
_hours.Value = Math.Floor(Maximum.TotalHours);
_minutes.Value = Maximum.Minutes;
_seconds.Value = Maximum.Seconds;
}
else if (value <= Minimum)
{
_hours.Value = Math.Floor(Minimum.TotalHours);
_minutes.Value = Minimum.Minutes;
_seconds.Value = Minimum.Seconds;
}
Value = value;
}
}
protected void UpdateOnValueChange()
{
if (this.IsLoaded)
{
TimeSpan value = Value;
if (value > Maximum)
{
value = Maximum;
}
else if (value < Minimum)
{
value = Minimum;
}
_hours.Value = Math.Floor(value.TotalHours);
_minutes.Value = value.Minutes;
_seconds.Value = value.Seconds;
}
}
protected void ValueChanged(NumberBox sender, NumberBoxValueChangedEventArgs args) => UpdateOnChanges();
protected static void ValuePropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) => ((TimeSpanControl)obj).UpdateOnValueChange();
protected static void RangePropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) => ((TimeSpanControl)obj).UpdateOnChanges();
protected void OnLoaded(object sender, RoutedEventArgs e) => UpdateOnValueChange();
#endregion
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB