Init commit
This commit is contained in:
41
Windows/ColorPickerWindow/ColorPickerView.xaml
Normal file
41
Windows/ColorPickerWindow/ColorPickerView.xaml
Normal file
@@ -0,0 +1,41 @@
|
||||
<Window x:Class="StructureHelper.ColorPickerView"
|
||||
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:StructureHelper"
|
||||
mc:Ignorable="d"
|
||||
d:DataContext="{d:DesignInstance local:ColorPickerViewModel}"
|
||||
Title="Выбрать цвет" Height="200" Width="500" Topmost="True" ResizeMode="NoResize">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="80"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="80"/>
|
||||
<ColumnDefinition Width="80"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10" Text="Красный"/>
|
||||
<Slider Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="10" Value="{Binding Red}" Minimum="0" Maximum="255"/>
|
||||
<TextBox Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="10" Text="{Binding Red}"/>
|
||||
|
||||
<Border Grid.Column="3" Grid.RowSpan="3" Margin="10" BorderBrush="Black" BorderThickness="1">
|
||||
<Rectangle Fill="{Binding SelectedColor}"/>
|
||||
</Border>
|
||||
|
||||
<TextBlock Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10" Text="Зеленый"/>
|
||||
<Slider Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="10" Value="{Binding Green}" Minimum="0" Maximum="255"/>
|
||||
<TextBox Grid.Row="1" Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="10" Text="{Binding Green}"/>
|
||||
|
||||
<TextBlock Grid.Row="2" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10" Text="Синий"/>
|
||||
<Slider Grid.Row="2" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="10" Value="{Binding Blue}" Minimum="0" Maximum="255"/>
|
||||
<TextBox Grid.Row="2" Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="10" Text="{Binding Blue}"/>
|
||||
|
||||
<Button Grid.Row="3" Grid.Column="2" Grid.ColumnSpan="2" Margin="10" VerticalAlignment="Center" HorizontalAlignment="Right" Content="Выбрать цвет" Command="{Binding SetColor}"/>
|
||||
</Grid>
|
||||
</Window>
|
||||
17
Windows/ColorPickerWindow/ColorPickerView.xaml.cs
Normal file
17
Windows/ColorPickerWindow/ColorPickerView.xaml.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.Windows;
|
||||
|
||||
namespace StructureHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Логика взаимодействия для ColorPickerView.xaml
|
||||
/// </summary>
|
||||
public partial class ColorPickerView : Window
|
||||
{
|
||||
public ColorPickerView(PrimitiveDefinition primitive)
|
||||
{
|
||||
var viewModel = new ColorPickerViewModel(primitive);
|
||||
DataContext = viewModel;
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
64
Windows/ColorPickerWindow/ColorPickerViewModel.cs
Normal file
64
Windows/ColorPickerWindow/ColorPickerViewModel.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using StructureHelper.Infrastructure;
|
||||
|
||||
namespace StructureHelper
|
||||
{
|
||||
public class ColorPickerViewModel : ViewModelBase
|
||||
{
|
||||
private int red, green, blue;
|
||||
|
||||
public int Red
|
||||
{
|
||||
get => red;
|
||||
set => OnColorItemChanged(value, ref red);
|
||||
}
|
||||
public int Green
|
||||
{
|
||||
get => green;
|
||||
set => OnColorItemChanged(value, ref green);
|
||||
}
|
||||
public int Blue
|
||||
{
|
||||
get => blue;
|
||||
set => OnColorItemChanged(value, ref blue);
|
||||
}
|
||||
|
||||
private SolidColorBrush selectedColor;
|
||||
public SolidColorBrush SelectedColor
|
||||
{
|
||||
get => selectedColor;
|
||||
set => OnPropertyChanged(value, selectedColor);
|
||||
}
|
||||
public ICommand SetColor { get; }
|
||||
public ColorPickerViewModel(PrimitiveDefinitionBase primitive)
|
||||
{
|
||||
if (primitive != null)
|
||||
{
|
||||
var solidBrush = primitive.Brush;
|
||||
Red = solidBrush.Color.R;
|
||||
Green = solidBrush.Color.G;
|
||||
Blue = solidBrush.Color.B;
|
||||
|
||||
SetColor = new RelayCommand(o => primitive.Brush = SelectedColor);
|
||||
}
|
||||
}
|
||||
private void OnColorItemChanged(int value, ref int colorItem, [CallerMemberName] string propertyName = null)
|
||||
{
|
||||
if (value >= 0 && value <= 255 && Math.Abs(colorItem - value) > 0.001)
|
||||
{
|
||||
colorItem = value;
|
||||
OnPropertyChanged(propertyName);
|
||||
UpdateSelectedColor();
|
||||
}
|
||||
}
|
||||
private void UpdateSelectedColor()
|
||||
{
|
||||
var color = Color.FromRgb((byte)Red, (byte)Green, (byte)Blue);
|
||||
SelectedColor = new SolidColorBrush(color);
|
||||
OnPropertyChanged(nameof(SelectedColor));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user