Skip to content
This repository was archived by the owner on Nov 27, 2024. It is now read-only.

Commit ff3d538

Browse files
committed
Trigger NotifyCollectionChanged event on in certain situations
1 parent 7ec35e0 commit ff3d538

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

OnnxStack.UI/Utils.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
using OnnxStack.StableDiffusion.Enums;
44
using OnnxStack.UI.Models;
55
using System;
6+
using System.Collections.ObjectModel;
67
using System.Diagnostics;
78
using System.IO;
89
using System.Reflection;
10+
using System.Runtime;
911
using System.Text.Json;
1012
using System.Text.Json.Serialization;
1113
using System.Threading;
@@ -208,5 +210,17 @@ public static void LogToWindow(string message)
208210
(System.Windows.Application.Current.MainWindow as MainWindow).UpdateOutputLog(message);
209211
}));
210212
}
213+
214+
215+
/// <summary>
216+
/// Forces the notify collection changed event.
217+
/// </summary>
218+
/// <typeparam name="T"></typeparam>
219+
/// <param name="collection">The collection.</param>
220+
public static void ForceNotifyCollectionChanged<T>(this ObservableCollection<T> collection)
221+
{
222+
// Hack: Moving an item will invoke a collection changed event
223+
collection?.Move(0, 0);
224+
}
211225
}
212226
}

OnnxStack.UI/Views/ModelSettingsView.xaml.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Diagnostics;
1313
using System.IO;
1414
using System.Linq;
15+
using System.Runtime;
1516
using System.Runtime.CompilerServices;
1617
using System.Text.Json.Serialization;
1718
using System.Threading;
@@ -538,6 +539,7 @@ private async Task UpdateStableDiffusionModel(ModelTemplateViewModel modelTempla
538539
stableDiffusionModel.ModelSet = modelSet;
539540
stableDiffusionModel.Name = modelSet.Name;
540541
SelectedModelTemplate.Name = modelSet.Name;
542+
UISettings.StableDiffusionModelSets.ForceNotifyCollectionChanged();
541543
await SaveConfigurationFile();
542544
}
543545
}
@@ -556,6 +558,7 @@ private async Task UpdateStableDiffusionModelAdvanced(ModelTemplateViewModel mod
556558
stableDiffusionModel.ModelSet = modelSet;
557559
stableDiffusionModel.Name = modelSet.Name;
558560
SelectedModelTemplate.Name = modelSet.Name;
561+
UISettings.StableDiffusionModelSets.ForceNotifyCollectionChanged();
559562
await SaveConfigurationFile();
560563
}
561564
}
@@ -613,6 +616,7 @@ private async Task UpdateUpscaleModel(ModelTemplateViewModel modelTemplate)
613616
upscaleModel.ModelSet = modelSet;
614617
upscaleModel.Name = modelSet.Name;
615618
SelectedModelTemplate.Name = modelSet.Name;
619+
UISettings.UpscaleModelSets.ForceNotifyCollectionChanged();
616620
await SaveConfigurationFile();
617621
}
618622
}
@@ -630,6 +634,7 @@ private async Task UpdateUpscaleModelAdvanced(ModelTemplateViewModel modelTempla
630634
upscaleModel.ModelSet = modelSet;
631635
upscaleModel.Name = modelSet.Name;
632636
SelectedModelTemplate.Name = modelSet.Name;
637+
UISettings.UpscaleModelSets.ForceNotifyCollectionChanged();
633638
await SaveConfigurationFile();
634639
}
635640
}

0 commit comments

Comments
 (0)