diff --git a/CV19/Components/GaugeIndicator.xaml b/CV19/Components/GaugeIndicator.xaml new file mode 100644 index 0000000..b5a31a3 --- /dev/null +++ b/CV19/Components/GaugeIndicator.xaml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/CV19/Components/GaugeIndicator.xaml.cs b/CV19/Components/GaugeIndicator.xaml.cs new file mode 100644 index 0000000..7ceb244 --- /dev/null +++ b/CV19/Components/GaugeIndicator.xaml.cs @@ -0,0 +1,66 @@ +using System; +using System.ComponentModel; +using System.Windows; + +namespace CV19.Components +{ + public partial class 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) + { + //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/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 519c66d..4d7280c 100644 --- a/CV19/ViewModels/MainWindowViewModel.cs +++ b/CV19/ViewModels/MainWindowViewModel.cs @@ -135,6 +135,26 @@ public string Status #endregion + #region FuelCount : double - Количество непонятно чего + + /// Количество непонятно чего + private double _FuelCount; + + /// Количество непонятно чего + public double FuelCount { get => _FuelCount; set => Set(ref _FuelCount, value); } + + #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 da1b901..4b0c00f 100644 --- a/CV19/Views/Windows/MainWindow.xaml +++ b/CV19/Views/Windows/MainWindow.xaml @@ -13,6 +13,8 @@ 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" + xmlns:converters="clr-namespace:CV19.Infrastructure.Converters" Title="{Binding Title}" DataContext="{Binding MainWindowModel, Source={StaticResource Locator}}" Width="800" Height="450"> @@ -55,7 +57,24 @@ - + + + + + + + + + + + +