Initial commit
This commit is contained in:
commit
589b3c096d
25
ColorPicker.sln
Normal file
25
ColorPicker.sln
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.5.33424.131
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ColorPicker", "ColorPicker\ColorPicker.csproj", "{566A4622-115B-4551-A4DF-FACAAA9926CB}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{566A4622-115B-4551-A4DF-FACAAA9926CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{566A4622-115B-4551-A4DF-FACAAA9926CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{566A4622-115B-4551-A4DF-FACAAA9926CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{566A4622-115B-4551-A4DF-FACAAA9926CB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {AFB26A20-AF6C-48B5-A073-4AEE2F70CA2F}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
9
ColorPicker/App.xaml
Normal file
9
ColorPicker/App.xaml
Normal file
@ -0,0 +1,9 @@
|
||||
<Application x:Class="ColorPicker.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:ColorPicker"
|
||||
StartupUri="MainWindow.xaml">
|
||||
<Application.Resources>
|
||||
|
||||
</Application.Resources>
|
||||
</Application>
|
17
ColorPicker/App.xaml.cs
Normal file
17
ColorPicker/App.xaml.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace ColorPicker
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
}
|
||||
}
|
10
ColorPicker/AssemblyInfo.cs
Normal file
10
ColorPicker/AssemblyInfo.cs
Normal file
@ -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)
|
||||
)]
|
14
ColorPicker/ColorPicker.csproj
Normal file
14
ColorPicker/ColorPicker.csproj
Normal file
@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWPF>true</UseWPF>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
14
ColorPicker/ColorPicker.csproj.user
Normal file
14
ColorPicker/ColorPicker.csproj.user
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup />
|
||||
<ItemGroup>
|
||||
<ApplicationDefinition Update="App.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Update="MainWindow.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
</Project>
|
83
ColorPicker/ColorPickerViewModel.cs
Normal file
83
ColorPicker/ColorPickerViewModel.cs
Normal file
@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.RightsManagement;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace ColorPicker.ViewModel
|
||||
{
|
||||
public partial class ColorPickerViewModel : ObservableObject
|
||||
{
|
||||
public ColorPickerViewModel()
|
||||
{
|
||||
red = 255;
|
||||
green = 0;
|
||||
blue = 0;
|
||||
CalculateHex();
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
byte red;
|
||||
|
||||
[ObservableProperty]
|
||||
byte green;
|
||||
|
||||
[ObservableProperty]
|
||||
byte blue;
|
||||
|
||||
[ObservableProperty]
|
||||
string hex;
|
||||
|
||||
[ObservableProperty]
|
||||
string hexInput;
|
||||
|
||||
bool lockEvents = false;
|
||||
|
||||
partial void OnRedChanged(byte value)
|
||||
{
|
||||
if (lockEvents) return;
|
||||
CalculateHex();
|
||||
}
|
||||
|
||||
partial void OnGreenChanged(byte value)
|
||||
{
|
||||
if (lockEvents) return;
|
||||
CalculateHex();
|
||||
}
|
||||
|
||||
partial void OnBlueChanged(byte value)
|
||||
{
|
||||
if (lockEvents) return;
|
||||
CalculateHex();
|
||||
}
|
||||
|
||||
partial void OnHexInputChanged(string value)
|
||||
{
|
||||
if (lockEvents || !Regex.IsMatch(value, @"^#[\dA-F]{6}$", RegexOptions.IgnoreCase))
|
||||
return;
|
||||
|
||||
Hex = HexInput;
|
||||
CalculateRGB();
|
||||
}
|
||||
|
||||
public void CalculateHex()
|
||||
{
|
||||
Hex = "#" + Red.ToString("X2") + Green.ToString("X2") + Blue.ToString("X2");
|
||||
HexInput = Hex;
|
||||
}
|
||||
|
||||
public void CalculateRGB()
|
||||
{
|
||||
lockEvents = true;
|
||||
Red = byte.Parse(Hex.Substring(1, 2), System.Globalization.NumberStyles.HexNumber);
|
||||
Green = byte.Parse(Hex.Substring(3, 2), System.Globalization.NumberStyles.HexNumber);
|
||||
Blue = byte.Parse(Hex.Substring(5, 2), System.Globalization.NumberStyles.HexNumber);
|
||||
lockEvents = false;
|
||||
}
|
||||
}
|
||||
}
|
37
ColorPicker/MainWindow.xaml
Normal file
37
ColorPicker/MainWindow.xaml
Normal file
@ -0,0 +1,37 @@
|
||||
<Window x:Class="ColorPicker.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:ColorPicker"
|
||||
xmlns:vm="clr-namespace:ColorPicker.ViewModel"
|
||||
mc:Ignorable="d"
|
||||
Title="MainWindow" Height="450" Width="800">
|
||||
<Window.Resources>
|
||||
<vm:ColorPickerViewModel x:Key="viewModel" />
|
||||
</Window.Resources>
|
||||
|
||||
<Grid DataContext="{StaticResource viewModel}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Rectangle Grid.Row="0" Grid.Column="0" Fill="{Binding Hex}" Stroke="Black" StrokeThickness="5" RadiusX="5" RadiusY="5" Margin="10,10,10,5" />
|
||||
<Label Grid.Row="1" Grid.Column="0" Content="{Binding Red}" ContentStringFormat="Red: {0}" Margin="10,5,10,5" />
|
||||
<Slider Grid.Row="2" Grid.Column="0" Maximum="255" Value="{Binding Red}" Margin="10,5,10,5" />
|
||||
<Label Grid.Row="3" Grid.Column="0" Content="{Binding Green}" ContentStringFormat="Green: {0}" Margin="10,5,10,5" />
|
||||
<Slider Grid.Row="4" Grid.Column="0" Maximum="255" Value="{Binding Green}" Margin="10,5,10,5" />
|
||||
<Label Grid.Row="5" Grid.Column="0" Content="{Binding Blue}" ContentStringFormat="Blue: {0}" Margin="10,5,10,5" />
|
||||
<Slider Grid.Row="6" Grid.Column="0" Maximum="255" Value="{Binding Blue}" Margin="10,5,10,5" />
|
||||
<TextBox Grid.Row="7" Grid.Column="0" Text="{Binding Path=HexInput, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="10,10,10,10" Padding="3" />
|
||||
</Grid>
|
||||
</Window>
|
28
ColorPicker/MainWindow.xaml.cs
Normal file
28
ColorPicker/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 ColorPicker
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user