HyperGraph

ц

12/3/2020 9:42:26 PM

Details

diff --git a/WPF/Common/WPF/Controls/NumericUpDown.xaml b/WPF/Common/WPF/Controls/NumericUpDown.xaml
new file mode 100644
index 0000000..1868671
--- /dev/null
+++ b/WPF/Common/WPF/Controls/NumericUpDown.xaml
@@ -0,0 +1,120 @@
+<UserControl x:Class="Common.WPF.Controls.NumericUpDown"
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+             xmlns:local="clr-namespace:Common.WPF.Controls"
+             mc:Ignorable="d"
+             x:Name="uc">
+    <UserControl.Resources>
+        <Style x:Key="FocusVisual">
+            <Setter Property="Control.Template">
+                <Setter.Value>
+                    <ControlTemplate>
+                        <Rectangle Margin="2" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
+                    </ControlTemplate>
+                </Setter.Value>
+            </Setter>
+        </Style>
+        <SolidColorBrush x:Key="Button.Static.Background" Color="#FFDDDDDD"/>
+        <SolidColorBrush x:Key="Button.Static.Border" Color="#FF707070"/>
+        <SolidColorBrush x:Key="Button.MouseOver.Background" Color="#FFBEE6FD"/>
+        <SolidColorBrush x:Key="Button.MouseOver.Border" Color="#FF3C7FB1"/>
+        <SolidColorBrush x:Key="Button.Pressed.Background" Color="#FFC4E5F6"/>
+        <SolidColorBrush x:Key="Button.Pressed.Border" Color="#FF2C628B"/>
+        <SolidColorBrush x:Key="Button.Disabled.Background" Color="#FFF4F4F4"/>
+        <SolidColorBrush x:Key="Button.Disabled.Border" Color="#FFADB2B5"/>
+        <SolidColorBrush x:Key="Button.Disabled.Foreground" Color="#FF838383"/>
+        <Style x:Key="BaseButtonStyle" TargetType="{x:Type ButtonBase}">
+            <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
+            <Setter Property="Background" Value="{StaticResource Button.Static.Background}"/>
+            <Setter Property="BorderBrush" Value="{StaticResource Button.Static.Border}"/>
+            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
+            <Setter Property="BorderThickness" Value="1"/>
+            <Setter Property="HorizontalContentAlignment" Value="Center"/>
+            <Setter Property="VerticalContentAlignment" Value="Center"/>
+            <Setter Property="Padding" Value="1"/>
+            <Setter Property="Template">
+                <Setter.Value>
+                    <ControlTemplate TargetType="{x:Type ButtonBase}">
+                        <Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
+                            <Canvas Height="10" VerticalAlignment="Center" Margin="1">
+                                <Path Stretch="Fill" Fill="Black" Data="M19.78,11.78L18.36,13.19L12,6.83L5.64,13.19L4.22,11.78L12,4L19.78,11.78Z" RenderTransformOrigin="0.5,0.5"/>
+                            </Canvas>
+                        </Border>
+                        <ControlTemplate.Triggers>
+                            <Trigger Property="Button.IsDefaulted" Value="true">
+                                <Setter Property="BorderBrush" TargetName="border" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
+                            </Trigger>
+                            <Trigger Property="IsMouseOver" Value="true">
+                                <Setter Property="Background" TargetName="border" Value="{StaticResource Button.MouseOver.Background}"/>
+                                <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.MouseOver.Border}"/>
+                            </Trigger>
+                            <Trigger Property="IsPressed" Value="true">
+                                <Setter Property="Background" TargetName="border" Value="{StaticResource Button.Pressed.Background}"/>
+                                <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.Pressed.Border}"/>
+                            </Trigger>
+                            <Trigger Property="IsEnabled" Value="false">
+                                <Setter Property="Background" TargetName="border" Value="{StaticResource Button.Disabled.Background}"/>
+                                <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.Disabled.Border}"/>
+                            </Trigger>
+                        </ControlTemplate.Triggers>
+                    </ControlTemplate>
+                </Setter.Value>
+            </Setter>
+        </Style>
+        <Style x:Key="BaseButtonStyle2" TargetType="{x:Type ButtonBase}" BasedOn="{StaticResource BaseButtonStyle}">
+            <Setter Property="Template">
+                <Setter.Value>
+                    <ControlTemplate TargetType="{x:Type ButtonBase}">
+                        <Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
+                            <Canvas Height="10" VerticalAlignment="Center" Margin="1">
+                                <Path Stretch="Fill" Fill="Black" Data="M19.78,11.78L18.36,13.19L12,6.83L5.64,13.19L4.22,11.78L12,4L19.78,11.78Z" RenderTransformOrigin="0.5,0.5">
+                                    <Path.RenderTransform>
+                                        <RotateTransform Angle="180"/>
+                                    </Path.RenderTransform>
+                                </Path>
+                            </Canvas>
+                        </Border>
+                        <ControlTemplate.Triggers>
+                            <Trigger Property="Button.IsDefaulted" Value="true">
+                                <Setter Property="BorderBrush" TargetName="border" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
+                            </Trigger>
+                            <Trigger Property="IsMouseOver" Value="true">
+                                <Setter Property="Background" TargetName="border" Value="{StaticResource Button.MouseOver.Background}"/>
+                                <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.MouseOver.Border}"/>
+                            </Trigger>
+                            <Trigger Property="IsPressed" Value="true">
+                                <Setter Property="Background" TargetName="border" Value="{StaticResource Button.Pressed.Background}"/>
+                                <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.Pressed.Border}"/>
+                            </Trigger>
+                            <Trigger Property="IsEnabled" Value="false">
+                                <Setter Property="Background" TargetName="border" Value="{StaticResource Button.Disabled.Background}"/>
+                                <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.Disabled.Border}"/>
+                            </Trigger>
+                        </ControlTemplate.Triggers>
+                    </ControlTemplate>
+                </Setter.Value>
+            </Setter>
+        </Style>
+        <Style x:Key="RepeatButtonStyleUpper" BasedOn="{StaticResource BaseButtonStyle}" TargetType="{x:Type RepeatButton}">
+            <Setter Property="Stylus.IsPressAndHoldEnabled" Value="false"/>
+        </Style>
+        <Style x:Key="RepeatButtonStyleDown" BasedOn="{StaticResource BaseButtonStyle2}" TargetType="{x:Type RepeatButton}">
+            <Setter Property="Stylus.IsPressAndHoldEnabled" Value="false"/>
+        </Style>
+    </UserControl.Resources>
+    <Grid>
+        <Grid.ColumnDefinitions>
+            <ColumnDefinition Width="*" />
+            <ColumnDefinition Width="20" />
+            <ColumnDefinition Width="20" />
+        </Grid.ColumnDefinitions>
+        <Grid.RowDefinitions>
+            <RowDefinition Height="26" />
+        </Grid.RowDefinitions>
+        <TextBox Name="NUDTextBox" Grid.Column="0" TextAlignment="Right" PreviewKeyDown="NUDTextBox_PreviewKeyDown" PreviewKeyUp="NUDTextBox_PreviewKeyUp" TextChanged="NUDTextBox_TextChanged" Margin="0,0,1,0" Text="{Binding MyText, ElementName=uc}"/>
+        <RepeatButton Name="NUDButtonUP"  Grid.Column="1" FontSize="8" FontFamily="Marlett" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Click="NUDButtonUP_Click" Style="{DynamicResource RepeatButtonStyleUpper}"/>
+        <RepeatButton Name="NUDButtonDown"  Grid.Column="2" FontSize="8"  FontFamily="Marlett" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Click="NUDButtonDown_Click" Style="{DynamicResource RepeatButtonStyleDown}"/>
+    </Grid>
+</UserControl>
diff --git a/WPF/Common/WPF/Controls/NumericUpDown.xaml.cs b/WPF/Common/WPF/Controls/NumericUpDown.xaml.cs
new file mode 100644
index 0000000..1545819
--- /dev/null
+++ b/WPF/Common/WPF/Controls/NumericUpDown.xaml.cs
@@ -0,0 +1,123 @@
+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.Reflection;
+
+namespace Common.WPF.Controls
+{
+    /// <summary>
+    /// Логика взаимодействия для NumericUpDown.xaml
+    /// </summary>
+    public partial class NumericUpDown : UserControl
+    {
+        public const int minvalue = 0,
+            maxvalue = 100,
+            startvalue = 0;
+
+        public NumericUpDown()
+        {
+            InitializeComponent();
+            NUDTextBox.Text = startvalue.ToString();
+        }
+
+        private void NUDButtonUP_Click(object sender, RoutedEventArgs e)
+        {
+            int number;
+            if (NUDTextBox.Text != "") number = Convert.ToInt32(NUDTextBox.Text);
+            else number = 0;
+            if (number < maxvalue)
+                NUDTextBox.Text = Convert.ToString(number + 1);
+        }
+
+        private void NUDButtonDown_Click(object sender, RoutedEventArgs e)
+        {
+            int number;
+            if (NUDTextBox.Text != "") number = Convert.ToInt32(NUDTextBox.Text);
+            else number = 0;
+            if (number > minvalue)
+                NUDTextBox.Text = Convert.ToString(number - 1);
+        }
+
+        private void NUDTextBox_PreviewKeyDown(object sender, KeyEventArgs e)
+        {
+
+            if (e.Key == Key.Up)
+            {
+                NUDButtonUP.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
+                typeof(Button).GetMethod("set_IsPressed", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(NUDButtonUP, new object[] { true });
+            }
+
+
+            if (e.Key == Key.Down)
+            {
+                NUDButtonDown.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
+                typeof(Button).GetMethod("set_IsPressed", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(NUDButtonDown, new object[] { true });
+            }
+        }
+
+        private void NUDTextBox_PreviewKeyUp(object sender, KeyEventArgs e)
+        {
+            if (e.Key == Key.Up)
+                typeof(Button).GetMethod("set_IsPressed", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(NUDButtonUP, new object[] { false });
+
+            if (e.Key == Key.Down)
+                typeof(Button).GetMethod("set_IsPressed", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(NUDButtonDown, new object[] { false });
+        }
+
+        private void NUDTextBox_TextChanged(object sender, TextChangedEventArgs e)
+        {
+            int number = 0;
+            if (NUDTextBox.Text != "")
+                if (!int.TryParse(NUDTextBox.Text, out number)) NUDTextBox.Text = startvalue.ToString();
+            if (number > maxvalue) NUDTextBox.Text = maxvalue.ToString();
+            if (number < minvalue) NUDTextBox.Text = minvalue.ToString();
+            NUDTextBox.SelectionStart = NUDTextBox.Text.Length;
+            //MyText = NUDTextBox.Text;
+        }
+
+        public string MyText
+        {
+            get { return (string)GetValue(MyTextBoxProperty); }
+            set { SetValue(MyTextBoxProperty, value); }
+        }
+
+        public static readonly DependencyProperty MyTextBoxProperty =
+           DependencyProperty.Register("NUDTextBox", typeof(string), 
+               typeof(NumericUpDown),
+               new UIPropertyMetadata("0", new PropertyChangedCallback(CurrentTextChanged))
+               );
+
+        private static void CurrentTextChanged(DependencyObject depObj, DependencyPropertyChangedEventArgs args)
+        {
+            NumericUpDown s = (NumericUpDown)depObj;
+            TextBox textBox = s.NUDTextBox;
+            textBox.Text = args.NewValue.ToString();
+
+            int number = 0;
+            if (textBox.Text != "")
+                if (!int.TryParse(textBox.Text, out number)) textBox.Text = startvalue.ToString();
+            if (number > maxvalue) textBox.Text = maxvalue.ToString();
+            if (number < minvalue) textBox.Text = minvalue.ToString();
+            textBox.SelectionStart = textBox.Text.Length;
+        }
+
+        public static bool ValidateCurrentNumber(object value)
+        {
+            if (Convert.ToInt32(value) >= 0 && Convert.ToInt32(value) <= 500)
+                return true;
+            else
+                return false;
+}
+
+    }
+}
diff --git a/WPF/View/MainWindow.xaml b/WPF/View/MainWindow.xaml
index 7d5b892..553a08c 100644
--- a/WPF/View/MainWindow.xaml
+++ b/WPF/View/MainWindow.xaml
@@ -5,6 +5,7 @@
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:local="clr-namespace:WPF.View"
         xmlns:converters="clr-namespace:Common.WPF.Converters"
+        xmlns:controls="clr-namespace:Common.WPF.Controls"
         WindowStartupLocation="CenterScreen"
         mc:Ignorable="d"
         x:Name="Window"
@@ -67,6 +68,7 @@
 
             <Grid.RowDefinitions>
                 <RowDefinition Height="Auto"/>
+                <RowDefinition Height="Auto"/>
                 <RowDefinition Height="*"/>
             </Grid.RowDefinitions>
             <Grid.ColumnDefinitions>
@@ -81,7 +83,11 @@
                     </DataTemplate>
                 </ComboBox.ItemTemplate>
             </ComboBox>
-            
+            <controls:NumericUpDown Grid.Row="1" Grid.Column="0" MyText="{Binding Path=TestNum, Converter={StaticResource IntToStringConverter}}">
+                
+            </controls:NumericUpDown>
+            <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding TestNum}"/>
+
         </Grid>
 
     </Grid>
diff --git a/WPF/ViewModel/MainViewModel.cs b/WPF/ViewModel/MainViewModel.cs
index c802607..1f32ef9 100644
--- a/WPF/ViewModel/MainViewModel.cs
+++ b/WPF/ViewModel/MainViewModel.cs
@@ -46,6 +46,17 @@ namespace WPF.ViewModel
             get => _selectedTheorem;
         }
 
+        private int _testNum;
+        public int TestNum
+        {
+            get => _testNum;
+            set
+            {
+                _testNum = value;
+                OnPropertyChanged(() => TestNum);
+            }
+        }
+
         #endregion
 
         #region Методы и команды

WPF/WPF.csproj 7(+7 -0)

diff --git a/WPF/WPF.csproj b/WPF/WPF.csproj
index 8bab0e8..6e9af91 100644
--- a/WPF/WPF.csproj
+++ b/WPF/WPF.csproj
@@ -69,6 +69,10 @@
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </Page>
+    <Page Include="Common\WPF\Controls\NumericUpDown.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="Common\WPF\Dictionary.xaml">
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
@@ -243,6 +247,9 @@
     <Compile Include="Common\WPF\Controls\TreeList\TreeList.cs" />
     <Compile Include="Common\WPF\Controls\TreeList\TreeListItem.cs" />
     <Compile Include="Common\WPF\Controls\TreeList\TreeNodeViewModel.cs" />
+    <Compile Include="Common\WPF\Controls\NumericUpDown.xaml.cs">
+      <DependentUpon>NumericUpDown.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Common\WPF\Converters\BoolToVisibilityConverter.cs" />
     <Compile Include="Common\WPF\Converters\CanExpandConverter.cs" />
     <Compile Include="Common\WPF\Converters\ColorToBrushConverter.cs" />