فهرست منبع

avalonia: Fixed Property changed notifications for tasks and qualifications

Kenric Nugteren 2 هفته پیش
والد
کامیت
6bec754184

+ 3 - 6
PRS.Avalonia/PRS.Avalonia/Modules/MyHR/MyHRQualifications/MyHRQualificationsEditView.axaml

@@ -16,17 +16,14 @@
                 <components:DateSelectorButton Grid.Row="0"
                                                Date="{Binding Shell.Qualified, Mode=TwoWay}"
                                                Prefix="Start:"
-                                               Prompt="Select Start Date"
-                                               DateChanged="Qualified_OnChanged"/>
+                                               Prompt="Select Start Date"/>
                 <components:DateSelectorButton Grid.Row="1"
                                                Date="{Binding Shell.Expiry, Mode=TwoWay}"
                                                Prefix="Expiry:"
-                                               Prompt="Select Expiry Date"
-                                               DateChanged="Expiry_OnChanged"/>
+                                               Prompt="Select Expiry Date"/>
                 <TextBox Grid.Row="2"
                          Text="{Binding Shell.Number}"
-                         Watermark="Number"
-                         TextChanged="Text_Changed"/>
+                         Watermark="Number"/>
             </Grid>
         </TabItem>
         <TabItem Header="Images">

+ 0 - 13
PRS.Avalonia/PRS.Avalonia/Modules/MyHR/MyHRQualifications/MyHRQualificationsEditView.axaml.cs

@@ -120,17 +120,4 @@ public partial class MyHRQualificationsEditView : UserControl
             return false;
         }
     }
-
-    private void Qualified_OnChanged(object sender, DateSelectorDateChangedEventArgs e)
-    {
-        ViewModel?.Changed(true);
-    }
-    private void Expiry_OnChanged(object sender, DateSelectorDateChangedEventArgs e)
-    {
-        ViewModel?.Changed(true);
-    }
-    private void Text_Changed(object sender, TextChangedEventArgs e)
-    {
-        ViewModel?.Changed(true);
-    }
 }

+ 5 - 2
PRS.Avalonia/PRS.Avalonia/Modules/MyHR/MyHRQualifications/MyHRQualificationsEditViewModel.cs

@@ -1,6 +1,7 @@
 using Avalonia.Media;
 using Comal.Classes;
 using CommunityToolkit.Mvvm.ComponentModel;
+using DynamicData.Binding;
 using InABox.Avalonia.Components;
 using InABox.Core;
 using System;
@@ -97,10 +98,10 @@ internal partial class MyHRQualificationsEditViewModel : ModuleViewModel
         return true;
     }
 
-    public void Changed(bool changed = false)
+    public void Changed()
     {
         if (Shell is null) return;
-        changed = changed || Shell.ID == Guid.Empty || Shell.IsChanged();
+        var changed = Shell.ID == Guid.Empty || Shell.IsChanged();
         SaveButton.IsVisible = changed;
         ImageMenuButton.IsVisible = SelectedTab == 1;
     }
@@ -113,6 +114,8 @@ internal partial class MyHRQualificationsEditViewModel : ModuleViewModel
     partial void OnShellChanged(EmployeeQualificationShell? value)
     {
         UpdateTitle(Shell?.Description ?? "Edit Qualification");
+
+        value?.WhenAnyPropertyChanged().Subscribe(shell => Changed());
     }
 
     protected override async Task<TimeSpan> OnRefresh()

+ 3 - 6
PRS.Avalonia/PRS.Avalonia/Modules/MyTasks/TaskEditView.axaml

@@ -14,15 +14,13 @@
             <Grid RowDefinitions="Auto,*,Auto,Auto,Auto,Auto,Auto">
                 <TextBox Watermark="Title"
                          Text="{Binding Shell.Title}"
-                         Grid.Row="0"
-                         TextChanged="TextBox_TextChanged"/>
+                         Grid.Row="0"/>
                 <TextBox Watermark="Task Description"
                          Text="{Binding Shell.Description}"
                          AcceptsReturn="True"
                          VerticalContentAlignment="Top"
                          IsEnabled="{Binding CanEditDescription}"
-                         Grid.Row="1"
-                         TextChanged="TextBox_TextChanged"/>
+                         Grid.Row="1"/>
                 <Button Classes="Standard"
                         Content="{Binding Shell.JobName, Converter={x:Static modules:TaskEditViewSelectButtonConverter.Instance}, ConverterParameter='Job'}"
                         Command="{Binding SelectJobCommand}"
@@ -34,8 +32,7 @@
                 <components:DateSelectorButton Prefix="Due:"
                                                Format="dd MMM yy"
                                                Date="{Binding Shell.DueDate, Mode=TwoWay}"
-                                               Grid.Row="4"
-                                               DateChanged="DateSelector_DateChanged"/>
+                                               Grid.Row="4"/>
                 <Button Classes="Standard"
                         Content="{Binding Shell.EmployeeName, Converter={x:Static modules:TaskEditViewSelectButtonConverter.Instance}, ConverterParameter='Employee'}"
                         Command="{Binding SelectEmployeeCommand}"

+ 0 - 10
PRS.Avalonia/PRS.Avalonia/Modules/MyTasks/TaskEditView.axaml.cs

@@ -58,14 +58,4 @@ public partial class TaskEditView : UserControl
             };
         }
     }
-
-    private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
-    {
-        ViewModel?.Changed();
-    }
-
-    private void DateSelector_DateChanged(object sender, DateSelectorDateChangedEventArgs e)
-    {
-        ViewModel?.Changed();
-    }
 }

+ 6 - 0
PRS.Avalonia/PRS.Avalonia/Modules/MyTasks/TaskEditViewModel.cs

@@ -3,6 +3,7 @@ using Avalonia.Media;
 using Comal.Classes;
 using CommunityToolkit.Mvvm.ComponentModel;
 using CommunityToolkit.Mvvm.Input;
+using DynamicData.Binding;
 using InABox.Avalonia;
 using InABox.Avalonia.Components;
 using InABox.Avalonia.Dialogs;
@@ -87,6 +88,11 @@ internal partial class TaskEditViewModel : ModuleViewModel
         DigitalForms = Repositories.DigitalForms();
     }
 
+    partial void OnShellChanged(IKanbanShell value)
+    {
+        value?.WhenAnyPropertyChanged().Subscribe(shell => Changed());
+    }
+
     protected override async Task<TimeSpan> OnRefresh()
     {
         CanEditDescription = Shell.ManagerID == Repositories.Me.ID;