Skip to content

Commit

Permalink
feat(converters): add DivisionMathConverter and update bindings (#32)
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
realybin authored Jan 22, 2025
1 parent 2debf4d commit c3145b4
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
30 changes: 30 additions & 0 deletions SketchNow/Converters/DivisionMathConverter.cs
Original file line number Diff line number Diff line change
@@ -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;

Check warning on line 12 in SketchNow/Converters/DivisionMathConverter.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

Check warning on line 12 in SketchNow/Converters/DivisionMathConverter.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

Check warning on line 12 in SketchNow/Converters/DivisionMathConverter.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

Check warning on line 12 in SketchNow/Converters/DivisionMathConverter.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

Check warning on line 12 in SketchNow/Converters/DivisionMathConverter.cs

View workflow job for this annotation

GitHub Actions / deploy-to-github-releases

Possible null reference return.

Check warning on line 12 in SketchNow/Converters/DivisionMathConverter.cs

View workflow job for this annotation

GitHub Actions / deploy-to-github-releases

Possible null reference return.

Check warning on line 12 in SketchNow/Converters/DivisionMathConverter.cs

View workflow job for this annotation

GitHub Actions / deploy-to-github-releases

Possible null reference return.

Check warning on line 12 in SketchNow/Converters/DivisionMathConverter.cs

View workflow job for this annotation

GitHub Actions / deploy-to-github-releases

Possible null reference return.

Check warning on line 12 in SketchNow/Converters/DivisionMathConverter.cs

View workflow job for this annotation

GitHub Actions / deploy-to-github-releases

Possible null reference return.

Check warning on line 12 in SketchNow/Converters/DivisionMathConverter.cs

View workflow job for this annotation

GitHub Actions / deploy-to-github-releases

Possible null reference return.

double number;
double divisor;

if (double.TryParse(value.ToString(), out number) && double.TryParse(parameter.ToString(), out divisor))
{
return number / divisor;
}

return null;

Check warning on line 22 in SketchNow/Converters/DivisionMathConverter.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

Check warning on line 22 in SketchNow/Converters/DivisionMathConverter.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

Check warning on line 22 in SketchNow/Converters/DivisionMathConverter.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

Check warning on line 22 in SketchNow/Converters/DivisionMathConverter.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.

Check warning on line 22 in SketchNow/Converters/DivisionMathConverter.cs

View workflow job for this annotation

GitHub Actions / deploy-to-github-releases

Possible null reference return.

Check warning on line 22 in SketchNow/Converters/DivisionMathConverter.cs

View workflow job for this annotation

GitHub Actions / deploy-to-github-releases

Possible null reference return.

Check warning on line 22 in SketchNow/Converters/DivisionMathConverter.cs

View workflow job for this annotation

GitHub Actions / deploy-to-github-releases

Possible null reference return.

Check warning on line 22 in SketchNow/Converters/DivisionMathConverter.cs

View workflow job for this annotation

GitHub Actions / deploy-to-github-releases

Possible null reference return.

Check warning on line 22 in SketchNow/Converters/DivisionMathConverter.cs

View workflow job for this annotation

GitHub Actions / deploy-to-github-releases

Possible null reference return.

Check warning on line 22 in SketchNow/Converters/DivisionMathConverter.cs

View workflow job for this annotation

GitHub Actions / deploy-to-github-releases

Possible null reference return.
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
9 changes: 6 additions & 3 deletions SketchNow/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -76,8 +76,11 @@
<Window.Style>
<StaticResource ResourceKey="MaterialDesignWindow" />
</Window.Style>
<Window.Resources>
<valueConverters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
</Window.Resources>
<Grid>
<Canvas Background="{Binding SelectedBrush}" Visibility="{Binding IsMultiPageMode, Converter={StaticResource BooleanToVisibilityConverter}}" />
<Canvas Background="{Binding SelectedBrush}" Visibility="{Binding IsMultiPageMode, Converter={StaticResource BoolToVisibilityConverter}}" />
<controls:CustomInkCanvas Background="Transparent"
Cursor="{Binding InkCanvasCursor}"
DefaultDrawingAttributes="{Binding CurrentDrawingAttributes}"
Expand Down Expand Up @@ -125,7 +128,7 @@
Margin="0,0,0,6"
VerticalAlignment="Bottom"
IsIndeterminate="{Binding Progress.IsIndeterminate}"
Visibility="{Binding Progress.IsVisible, Converter={StaticResource BooleanToVisibilityConverter}}"
Visibility="{Binding Progress.IsVisible, Converter={StaticResource BoolToVisibilityConverter}}"
Value="{Binding Progress.Value}" />
</Grid>
</Window>
6 changes: 5 additions & 1 deletion SketchNow/Views/PageNavigationView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
<UserControl.Resources>
<valueConverters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
</UserControl.Resources>
<StackPanel Margin="5"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
Background="#09000000"
Orientation="Horizontal"
Visibility="{Binding IsMultiPageMode, Converter={StaticResource BooleanToVisibilityConverter}}">
Visibility="{Binding IsMultiPageMode, Converter={StaticResource BoolToVisibilityConverter}}">
<Button Height="48"
Command="{Binding CanvasPages.PreviousCommand}"
Content="{materialDesign:PackIcon Kind=ArrowLeft}"
Expand Down
5 changes: 4 additions & 1 deletion SketchNow/Views/ToolBarView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:properties="clr-namespace:SketchNow.Properties"
xmlns:valueConverters="http://schemas.superdev.ch/valueconverters/2016/xaml"
xmlns:vms="clr-namespace:SketchNow.ViewModels"
x:Name="TooBarControl"
d:DataContext="{d:DesignInstance IsDesignTimeCreatable=False,
Expand All @@ -17,8 +18,10 @@
d:DesignWidth="800"
mc:Ignorable="d">
<UserControl.Resources>
<valueConverters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
<converters:ColorToBrushConverter x:Key="ColorToBrushConverter" />
<converters:EnumToIndexConverter x:Key="EnumToIndexConverter" />
<converters:DivisionMathConverter x:Key="DivisionMathConverter" />
</UserControl.Resources>
<jas:DragCanvas>
<StackPanel Canvas.Left="{Binding (Canvas.Left), ElementName=ToolBar, ConverterParameter=81, Converter={StaticResource MathAddConverter}}"
Expand Down Expand Up @@ -91,7 +94,7 @@
Canvas.Top="{Binding (Canvas.Top), ConverterParameter=-36, Converter={StaticResource MathAddConverter}, ElementName=ToolBar}"
jas:DragCanvas.CanBeDragged="False"
Orientation="Horizontal"
Visibility="{Binding IsSelected, Converter={StaticResource BooleanToVisibilityConverter}, ElementName=ToolBarPen}">
Visibility="{Binding IsSelected, Converter={StaticResource BoolToVisibilityConverter}, ElementName=ToolBarPen}">
<ListBox x:Name="ColorList"
Margin="1"
ItemsSource="{Binding ColorList}"
Expand Down

0 comments on commit c3145b4

Please sign in to comment.