From 8bcd109b5d02e49915e1d24bc8cf186e317fa718 Mon Sep 17 00:00:00 2001 From: Infarh Date: Sat, 6 Jun 2020 16:39:39 +0300 Subject: [PATCH 1/3] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D0=BE=D1=82=D0=BE=D0=B2?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=B2=D0=B8=D0=B7=D1=83=D0=B0=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D0=BE=D0=B3=D0=BE=20=D1=8D=D0=BB=D0=B5=D0=BC=D0=B5=D0=BD=D1=82?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CV19/Components/GaugeIndicator.xaml | 40 ++++++++++++++++++++++++++ CV19/Components/GaugeIndicator.xaml.cs | 26 +++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 CV19/Components/GaugeIndicator.xaml create mode 100644 CV19/Components/GaugeIndicator.xaml.cs diff --git a/CV19/Components/GaugeIndicator.xaml b/CV19/Components/GaugeIndicator.xaml new file mode 100644 index 0000000..ebbece7 --- /dev/null +++ b/CV19/Components/GaugeIndicator.xaml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/CV19/Components/GaugeIndicator.xaml.cs b/CV19/Components/GaugeIndicator.xaml.cs new file mode 100644 index 0000000..ce1d245 --- /dev/null +++ b/CV19/Components/GaugeIndicator.xaml.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Text; +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 CV19.Components +{ + /// + /// Логика взаимодействия для GaugeIndicator.xaml + /// + public partial class GaugeIndicator : UserControl + { + public GaugeIndicator() + { + InitializeComponent(); + } + } +} From a69b2febd6e12ca77c2b86991340ef5f62658521 Mon Sep 17 00:00:00 2001 From: Infarh Date: Sat, 6 Jun 2020 17:07:26 +0300 Subject: [PATCH 2/3] =?UTF-8?q?=D0=9E=D0=BF=D1=80=D0=B5=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=81=D0=B2=D0=BE=D0=B9=D1=81=D1=82?= =?UTF-8?q?=D0=B2=D0=B0-=D0=B7=D0=B0=D0=B2=D0=B8=D1=81=D0=B8=D0=BC=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CV19/Components/GaugeIndicator.xaml | 3 +- CV19/Components/GaugeIndicator.xaml.cs | 72 ++++++++++++++++++++------ CV19/ViewModels/MainWindowViewModel.cs | 10 ++++ CV19/Views/Windows/MainWindow.xaml | 8 ++- 4 files changed, 75 insertions(+), 18 deletions(-) diff --git a/CV19/Components/GaugeIndicator.xaml b/CV19/Components/GaugeIndicator.xaml index ebbece7..b5a31a3 100644 --- a/CV19/Components/GaugeIndicator.xaml +++ b/CV19/Components/GaugeIndicator.xaml @@ -30,7 +30,8 @@ - + diff --git a/CV19/Components/GaugeIndicator.xaml.cs b/CV19/Components/GaugeIndicator.xaml.cs index ce1d245..7ceb244 100644 --- a/CV19/Components/GaugeIndicator.xaml.cs +++ b/CV19/Components/GaugeIndicator.xaml.cs @@ -1,26 +1,66 @@ using System; -using System.Collections.Generic; -using System.Text; +using System.ComponentModel; 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 CV19.Components { - /// - /// Логика взаимодействия для GaugeIndicator.xaml - /// - public partial class GaugeIndicator : UserControl + public partial class GaugeIndicator { - public GaugeIndicator() + #region ValueProperty + + public static readonly DependencyProperty ValueProperty = + DependencyProperty.Register( + nameof(Value), + typeof(double), + typeof(GaugeIndicator), + new PropertyMetadata( + default(double), + OnValuePropertyChanged, + OnCoerceValue), + OnValidateValue); + + private static bool OnValidateValue(object O) + { + return true; + } + + private static object OnCoerceValue(DependencyObject D, object Basevalue) + { + var value = (double) Basevalue; + return Math.Max(0, Math.Min(100, value)); + } + + private static void OnValuePropertyChanged(DependencyObject D, DependencyPropertyChangedEventArgs E) { - InitializeComponent(); + //var gauge_indicator = (GaugeIndicator) D; + //gauge_indicator.ArrowRotator.Angle = (double) E.NewValue; } + + public double Value + { + get => (double)GetValue(ValueProperty); + set => SetValue(ValueProperty, value); + } + + #endregion + + #region Angle : double - Какой-то угол + + /// Какой-то угол + public static readonly DependencyProperty AngleProperty = + DependencyProperty.Register( + nameof(Angle), + typeof(double), + typeof(GaugeIndicator), + new PropertyMetadata(default(double))); + + /// Какой-то угол + [Category("Моя категория!")] + [Description("Какой-то угол")] + public double Angle { get => (double) GetValue(AngleProperty); set => SetValue(AngleProperty, value); } + + #endregion + + public GaugeIndicator() => InitializeComponent(); } } diff --git a/CV19/ViewModels/MainWindowViewModel.cs b/CV19/ViewModels/MainWindowViewModel.cs index 519c66d..88fb60f 100644 --- a/CV19/ViewModels/MainWindowViewModel.cs +++ b/CV19/ViewModels/MainWindowViewModel.cs @@ -135,6 +135,16 @@ public string Status #endregion + #region FuelCount : double - Количество непонятно чего + + /// Количество непонятно чего + private double _FuelCount; + + /// Количество непонятно чего + public double FuelCount { get => _FuelCount; set => Set(ref _FuelCount, value); } + + #endregion + public IEnumerable TestStudents => Enumerable.Range(1, App.IsDesignMode ? 10 : 100_000) .Select(i => new Student diff --git a/CV19/Views/Windows/MainWindow.xaml b/CV19/Views/Windows/MainWindow.xaml index da1b901..991ff51 100644 --- a/CV19/Views/Windows/MainWindow.xaml +++ b/CV19/Views/Windows/MainWindow.xaml @@ -13,6 +13,7 @@ xmlns:sys="clr-namespace:System;assembly=System.Runtime" xmlns:cm="clr-namespace:System.ComponentModel;assembly=WindowsBase" xmlns:system="clr-namespace:System;assembly=System.Runtime.Extensions" + xmlns:components="clr-namespace:CV19.Components" Title="{Binding Title}" DataContext="{Binding MainWindowModel, Source={StaticResource Locator}}" Width="800" Height="450"> @@ -55,7 +56,12 @@ - + + + + From bfd29cbd9ce780e8081d5b1b34bd3d8cf7533d3e Mon Sep 17 00:00:00 2001 From: Infarh Date: Sat, 6 Jun 2020 17:32:45 +0300 Subject: [PATCH 3/3] =?UTF-8?q?=D0=9A=D0=BE=D0=BD=D0=B2=D0=B5=D1=80=D1=82?= =?UTF-8?q?=D0=B5=D1=80=20=D1=81=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6?= =?UTF-8?q?=D0=BD=D0=BE=D1=81=D1=82=D1=8C=D1=8E=20=D0=BF=D1=80=D0=B8=D0=B2?= =?UTF-8?q?=D1=8F=D0=B7=D0=BA=D0=B8=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Converters/DebugConverter.cs | 22 ++++++++++ .../ParametricMultiplicityValueConverter.cs | 44 +++++++++++++++++++ CV19/ViewModels/Base/ViewModel.cs | 4 +- CV19/ViewModels/MainWindowViewModel.cs | 10 +++++ CV19/Views/Windows/MainWindow.xaml | 19 ++++++-- 5 files changed, 94 insertions(+), 5 deletions(-) create mode 100644 CV19/Infrastructure/Converters/DebugConverter.cs create mode 100644 CV19/Infrastructure/Converters/ParametricMultiplicityValueConverter.cs diff --git a/CV19/Infrastructure/Converters/DebugConverter.cs b/CV19/Infrastructure/Converters/DebugConverter.cs new file mode 100644 index 0000000..1fb3dfd --- /dev/null +++ b/CV19/Infrastructure/Converters/DebugConverter.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Text; + +namespace CV19.Infrastructure.Converters +{ + internal class DebugConverter : Converter + { + public override object Convert(object v, Type t, object p, CultureInfo c) + { + System.Diagnostics.Debugger.Break(); + return v; + } + + public override object ConvertBack(object v, Type t, object p, CultureInfo c) + { + System.Diagnostics.Debugger.Break(); + return v; + } + } +} diff --git a/CV19/Infrastructure/Converters/ParametricMultiplicityValueConverter.cs b/CV19/Infrastructure/Converters/ParametricMultiplicityValueConverter.cs new file mode 100644 index 0000000..31c07c7 --- /dev/null +++ b/CV19/Infrastructure/Converters/ParametricMultiplicityValueConverter.cs @@ -0,0 +1,44 @@ +using System; +using System.ComponentModel; +using System.Globalization; +using System.Windows; +using System.Windows.Data; + +namespace CV19.Infrastructure.Converters +{ + internal class ParametricMultiplicityValueConverter : Freezable, IValueConverter + { + #region Value : double - Прибавляемое значение + + /// Прибавляемое значение + public static readonly DependencyProperty ValueProperty = + DependencyProperty.Register( + nameof(Value), + typeof(double), + typeof(ParametricMultiplicityValueConverter), + new PropertyMetadata(1.0/*, (d,e) => { }*/)); + + /// Прибавляемое значение + //[Category("")] + [Description("Прибавляемое значение")] + public double Value { get => (double) GetValue(ValueProperty); set => SetValue(ValueProperty, value); } + + #endregion + + public object Convert(object v, Type t, object p, CultureInfo c) + { + var value = System.Convert.ToDouble(v, c); + + return value * Value; + } + + public object ConvertBack(object v, Type t, object p, CultureInfo c) + { + var value = System.Convert.ToDouble(v, c); + + return value / Value; + } + + protected override Freezable CreateInstanceCore() => new ParametricMultiplicityValueConverter { Value = Value }; + } +} diff --git a/CV19/ViewModels/Base/ViewModel.cs b/CV19/ViewModels/Base/ViewModel.cs index 4761594..bba0f2e 100644 --- a/CV19/ViewModels/Base/ViewModel.cs +++ b/CV19/ViewModels/Base/ViewModel.cs @@ -41,9 +41,9 @@ public override object ProvideValue(IServiceProvider sp) private WeakReference _TargetRef; private WeakReference _RootRef; - public object TargetObject => _TargetRef.Target; + public object TargetObject => _TargetRef?.Target; - public object RootObject => _RootRef.Target; + public object RootObject => _RootRef?.Target; protected virtual void OnInitialized(object Target, object Property, object Root) { diff --git a/CV19/ViewModels/MainWindowViewModel.cs b/CV19/ViewModels/MainWindowViewModel.cs index 88fb60f..4d7280c 100644 --- a/CV19/ViewModels/MainWindowViewModel.cs +++ b/CV19/ViewModels/MainWindowViewModel.cs @@ -145,6 +145,16 @@ public string Status #endregion + #region Coefficient : double - Коэффициент + + /// Коэффициент + private double _Coefficient = 1; + + /// Коэффициент + public double Coefficient { get => _Coefficient; set => Set(ref _Coefficient, value); } + + #endregion + public IEnumerable TestStudents => Enumerable.Range(1, App.IsDesignMode ? 10 : 100_000) .Select(i => new Student diff --git a/CV19/Views/Windows/MainWindow.xaml b/CV19/Views/Windows/MainWindow.xaml index 991ff51..4b0c00f 100644 --- a/CV19/Views/Windows/MainWindow.xaml +++ b/CV19/Views/Windows/MainWindow.xaml @@ -14,6 +14,7 @@ xmlns:cm="clr-namespace:System.ComponentModel;assembly=WindowsBase" xmlns:system="clr-namespace:System;assembly=System.Runtime.Extensions" xmlns:components="clr-namespace:CV19.Components" + xmlns:converters="clr-namespace:CV19.Infrastructure.Converters" Title="{Binding Title}" DataContext="{Binding MainWindowModel, Source={StaticResource Locator}}" Width="800" Height="450"> @@ -57,10 +58,22 @@ + + + - + Width="80" Height="80"> + + + + + +