From c3145b44f4dcbbe365fab73ccf7a6527a01c7d7b Mon Sep 17 00:00:00 2001 From: Bin Date: Thu, 23 Jan 2025 00:46:38 +0800 Subject: [PATCH] feat(converters): add DivisionMathConverter and update bindings (#32) - Introduced `DivisionMathConverter` for division operations in data binding. - Updated `MainWindow.xaml`, `PageNavigationView.xaml`, and `ToolBarView.xaml` to use the new `BoolToVisibilityConverter`. - Replaced old visibility converter references to ensure consistency across the application. --- SketchNow/Converters/DivisionMathConverter.cs | 30 +++++++++++++++++++ SketchNow/Views/MainWindow.xaml | 9 ++++-- SketchNow/Views/PageNavigationView.xaml | 6 +++- SketchNow/Views/ToolBarView.xaml | 5 +++- 4 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 SketchNow/Converters/DivisionMathConverter.cs diff --git a/SketchNow/Converters/DivisionMathConverter.cs b/SketchNow/Converters/DivisionMathConverter.cs new file mode 100644 index 0000000..3010979 --- /dev/null +++ b/SketchNow/Converters/DivisionMathConverter.cs @@ -0,0 +1,30 @@ +using System; +using System.Globalization; +using System.Windows.Data; + +namespace SketchNow.Converters +{ + public class DivisionMathConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value == null || parameter == null) + return null; + + double number; + double divisor; + + if (double.TryParse(value.ToString(), out number) && double.TryParse(parameter.ToString(), out divisor)) + { + return number / divisor; + } + + return null; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/SketchNow/Views/MainWindow.xaml b/SketchNow/Views/MainWindow.xaml index a078523..35f352e 100644 --- a/SketchNow/Views/MainWindow.xaml +++ b/SketchNow/Views/MainWindow.xaml @@ -9,7 +9,7 @@ xmlns:properties="clr-namespace:SketchNow.Properties" xmlns:system="clr-namespace:System;assembly=System.Runtime" xmlns:views="clr-namespace:SketchNow.Views" - xmlns:vms="clr-namespace:SketchNow.ViewModels" + xmlns:vms="clr-namespace:SketchNow.ViewModels" xmlns:valueConverters="http://schemas.superdev.ch/valueconverters/2016/xaml" Title="SketchNow" Width="800" Height="450" @@ -76,8 +76,11 @@ + + + - + \ No newline at end of file diff --git a/SketchNow/Views/PageNavigationView.xaml b/SketchNow/Views/PageNavigationView.xaml index cfb68c5..a5d3ea7 100644 --- a/SketchNow/Views/PageNavigationView.xaml +++ b/SketchNow/Views/PageNavigationView.xaml @@ -5,18 +5,22 @@ xmlns:local="clr-namespace:SketchNow.Views" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:valueConverters="http://schemas.superdev.ch/valueconverters/2016/xaml" xmlns:vms="clr-namespace:SketchNow.ViewModels" d:DataContext="{d:DesignInstance IsDesignTimeCreatable=False, Type={x:Type vms:MainWindowViewModel}}" d:DesignHeight="300" d:DesignWidth="800" mc:Ignorable="d"> + + + + Visibility="{Binding IsMultiPageMode, Converter={StaticResource BoolToVisibilityConverter}}">