Add project files.
This commit is contained in:
parent
646b39ed3f
commit
bb00a9340f
13
.idea/.idea.ColorPicker/.idea/.gitignore
vendored
Normal file
13
.idea/.idea.ColorPicker/.idea/.gitignore
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Rider ignored files
|
||||
/contentModel.xml
|
||||
/.idea.ColorPicker.iml
|
||||
/modules.xml
|
||||
/projectSettingsUpdater.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
4
.idea/.idea.ColorPicker/.idea/encodings.xml
Normal file
4
.idea/.idea.ColorPicker/.idea/encodings.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
|
||||
</project>
|
8
.idea/.idea.ColorPicker/.idea/indexLayout.xml
Normal file
8
.idea/.idea.ColorPicker/.idea/indexLayout.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="UserContentModel">
|
||||
<attachedFolders />
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
</component>
|
||||
</project>
|
9
App.xaml
Normal file
9
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>
|
6
App.xaml.cs
Normal file
6
App.xaml.cs
Normal file
@ -0,0 +1,6 @@
|
||||
using System.Windows;
|
||||
|
||||
namespace ColorPicker;
|
||||
|
||||
public partial class App : Application {
|
||||
}
|
10
AssemblyInfo.cs
Normal file
10
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)
|
||||
)]
|
20
ColorPicker.csproj
Normal file
20
ColorPicker.csproj
Normal file
@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net7.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWPF>true</UseWPF>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Models\" />
|
||||
<Folder Include="Views\" />
|
||||
<Folder Include="ViewModels\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
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.csproj", "{527B253E-F795-40CE-9E4F-030717FB109B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{527B253E-F795-40CE-9E4F-030717FB109B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{527B253E-F795-40CE-9E4F-030717FB109B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{527B253E-F795-40CE-9E4F-030717FB109B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{527B253E-F795-40CE-9E4F-030717FB109B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {C45379AD-6848-4D51-9A8D-2866C04E946E}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
39
MainWindow.xaml
Normal file
39
MainWindow.xaml
Normal file
@ -0,0 +1,39 @@
|
||||
<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:vm="clr-namespace:ColorPicker.ViewModels"
|
||||
mc:Ignorable="d"
|
||||
Title="MainWindow" Height="600" Width="400">
|
||||
<Window.Resources>
|
||||
<vm:ColorPickerViewModel x:Key="viewModel"/>
|
||||
</Window.Resources>
|
||||
<Grid DataContext="{StaticResource viewModel}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="4*"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="8*" />
|
||||
|
||||
</Grid.ColumnDefinitions>
|
||||
<Rectangle Fill="{Binding Color}" Margin="10" Name="RGBColor" Grid.Row="0" Grid.ColumnSpan="2"/>
|
||||
<Label Content="Red" Grid.Row="1"/>
|
||||
<Label Content="Green" Grid.Row="2"/>
|
||||
<Label Content="Blue" Grid.Row="3"/>
|
||||
<Slider Name="RedSlider" Maximum="255" Grid.Row="1" Grid.Column="1" Value="{Binding Red}" />
|
||||
<Slider Name="GreenSlider" Maximum="255" Grid.Row="2" Grid.Column="1" Value="{Binding Green}"/>
|
||||
<Slider Name="BlueSlider" Maximum="255" Grid.Row="3" Grid.Column="1" Value="{Binding Blue}"/>
|
||||
<TextBox
|
||||
Name="RGBInHex"
|
||||
Grid.Row="4"
|
||||
Grid.ColumnSpan="2"
|
||||
Margin="10"
|
||||
Text="{Binding Path=HexInput, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
|
||||
</Grid>
|
||||
</Window>
|
9
MainWindow.xaml.cs
Normal file
9
MainWindow.xaml.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using System.Windows;
|
||||
|
||||
namespace ColorPicker;
|
||||
|
||||
public partial class MainWindow : Window {
|
||||
public MainWindow() {
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
39
ViewModels/ColorPicker.cs
Normal file
39
ViewModels/ColorPicker.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace ColorPicker.ViewModels;
|
||||
|
||||
public partial class ColorPickerViewModel : ObservableObject {
|
||||
|
||||
[ObservableProperty]
|
||||
private byte red = 0, green = 0, blue = 0;
|
||||
|
||||
[ObservableProperty]
|
||||
private string color = "#000000", hexInput = "#000000";
|
||||
|
||||
public ColorPickerViewModel() {
|
||||
calculateColorFromRgb();
|
||||
}
|
||||
|
||||
partial void OnRedChanged(byte value) => calculateColorFromRgb();
|
||||
partial void OnGreenChanged(byte value) => calculateColorFromRgb();
|
||||
partial void OnBlueChanged(byte value) => calculateColorFromRgb();
|
||||
|
||||
partial void OnHexInputChanged(string value) {
|
||||
if (!Regex.IsMatch(value, @"^#[\dA-F]{6}$", RegexOptions.IgnoreCase))
|
||||
return;
|
||||
this.Color = HexInput;
|
||||
calculateRgbFromColor();
|
||||
}
|
||||
|
||||
private void calculateRgbFromColor() {
|
||||
var parse = (int start, int length) => byte.Parse(this.Color.Substring(start, length), System.Globalization.NumberStyles.HexNumber);
|
||||
(this.Red, this.Green, this.Blue) = (parse(1, 2), parse(3, 2), parse(5, 2));
|
||||
}
|
||||
|
||||
private void calculateColorFromRgb() {
|
||||
this.Color = $"#{this.Red:X2}{this.Green:X2}{this.Blue:X2}";
|
||||
this.HexInput = this.Color;
|
||||
}
|
||||
|
||||
}
|
7
global.json
Normal file
7
global.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"sdk": {
|
||||
"version": "7.0.0",
|
||||
"rollForward": "latestMajor",
|
||||
"allowPrerelease": true
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user