diff --git a/HLab/MonitorVcp/HLab.Windows.MonitorVcp.csproj b/HLab/MonitorVcp/HLab.Windows.MonitorVcp.csproj
index 4374d462..3272ee84 100644
--- a/HLab/MonitorVcp/HLab.Windows.MonitorVcp.csproj
+++ b/HLab/MonitorVcp/HLab.Windows.MonitorVcp.csproj
@@ -128,6 +128,7 @@
+
diff --git a/HLab/MonitorVcp/app.config b/HLab/MonitorVcp/app.config
new file mode 100644
index 00000000..724d290a
--- /dev/null
+++ b/HLab/MonitorVcp/app.config
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/HLab/Mvvm/HLab.Mvvm.csproj b/HLab/Mvvm/HLab.Mvvm.csproj
index 3570efdc..0f8a864e 100644
--- a/HLab/Mvvm/HLab.Mvvm.csproj
+++ b/HLab/Mvvm/HLab.Mvvm.csproj
@@ -72,8 +72,20 @@
+
+ ..\..\packages\Swordfish.NET.CollectionsV3.3.0.0.1\lib\net45\Swordfish.NET.dll
+
+
+ ..\..\packages\Swordfish.NET.CollectionsV3.3.0.0.1\lib\net45\Swordfish.NET.CollectionsV3.dll
+
+
+ ..\..\packages\System.Collections.Immutable.1.4.0\lib\netstandard2.0\System.Collections.Immutable.dll
+
+
+
+
@@ -139,15 +151,21 @@
+
+
Always
+
+
+
+
\ No newline at end of file
diff --git a/HLab/Mvvm/Icons/IconService.cs b/HLab/Mvvm/Icons/IconService.cs
index 14e1d27b..8896687e 100644
--- a/HLab/Mvvm/Icons/IconService.cs
+++ b/HLab/Mvvm/Icons/IconService.cs
@@ -8,6 +8,7 @@
using System.Text;
using System.Windows;
using System.Windows.Controls;
+using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Xml;
@@ -54,6 +55,9 @@ public UIElement GetIcon(string assemblyName, string name)
}
public UIElement GetIcon(Assembly assembly, string name)
{
+
+ return GetIconXaml(assembly, name) ?? GetFromSvg(assembly, name);
+
var cache = _cache.GetValue(assembly, a => new IconCache(a));
return cache.Get(name,(a,n)=> GetIconXaml(a, n) ?? GetFromSvg(a, n));
@@ -74,13 +78,14 @@ public UIElement GetIconXaml(Assembly assembly, string name)
}
}
- private XslCompiledTransform _transform;
+ private XslCompiledTransform _transformSvg;
+ private XslCompiledTransform _transformHtml;
- private XslCompiledTransform Transform
+ private XslCompiledTransform TransformSvg
{
get
{
- if (_transform == null)
+ if (_transformSvg == null)
{
using (var xslStream = Assembly.GetAssembly(this.GetType())
.GetManifestResourceStream("HLab.Mvvm.Icons.svg2xaml.xsl"))
@@ -89,14 +94,74 @@ private XslCompiledTransform Transform
using (var stylesheet = XmlReader.Create(xslStream))
{
var settings = new XsltSettings { EnableDocumentFunction = true };
- _transform = new XslCompiledTransform();
- _transform.Load(stylesheet, settings, new XmlUrlResolver());
+ _transformSvg = new XslCompiledTransform();
+ _transformSvg.Load(stylesheet, settings, new XmlUrlResolver());
}
}
}
- return _transform;
+ return _transformSvg;
}
}
+ private XslCompiledTransform TransformHtml
+ {
+ get
+ {
+ if (_transformHtml == null)
+ {
+ using (var xslStream = Assembly.GetAssembly(this.GetType())
+ .GetManifestResourceStream("HLab.Mvvm.Icons.html2xaml.xslt"))
+ {
+ if (xslStream == null) throw new IOException("xsl file not found");
+ using (var stylesheet = XmlReader.Create(xslStream))
+ {
+ var settings = new XsltSettings { EnableDocumentFunction = true };
+ _transformHtml = new XslCompiledTransform();
+ _transformHtml.Load(stylesheet, settings, new XmlUrlResolver());
+ }
+ }
+ }
+ return _transformHtml;
+ }
+ }
+
+ public TextBlock GetFromHtml(string html)
+ {
+ TextBlock textBlock = null;
+ Application.Current.Dispatcher.Invoke(
+ () =>
+ {
+ using (var s = new MemoryStream())
+ {
+ using (var stringReader = new StringReader(html))
+ {
+ using (var htmlReader = XmlReader.Create(stringReader))
+ {
+ using (var w = XmlWriter.Create(s))
+ {
+ TransformHtml.Transform(htmlReader, w);
+ }
+
+ try
+ {
+ s.Seek(0, SeekOrigin.Begin);
+
+ var sz = Encoding.UTF8.GetString(s.ToArray());
+ using (var reader = XmlReader.Create(s))
+ {
+ textBlock = (TextBlock) System.Windows.Markup.XamlReader.Load(reader);
+ // Code to run on the GUI thread.
+ }
+
+ }
+ catch (IOException)
+ {
+ }
+ }
+ }
+ }
+ });
+ return textBlock;
+ }
public UIElement GetFromSvg(Assembly assembly, string name)
{
@@ -112,15 +177,18 @@ public UIElement GetFromSvg(Assembly assembly, string name)
{
using (var w = XmlWriter.Create(s))
{
- Transform.Transform(svgReader, w);
+ TransformSvg.Transform(svgReader, w);
}
try
{
s.Seek(0, SeekOrigin.Begin);
- var sz = Encoding.UTF8.GetString(s.ToArray());
+ //var sz = Encoding.UTF8.GetString(s.ToArray());
using (var reader = XmlReader.Create(s))
- return (UIElement) System.Windows.Markup.XamlReader.Load(reader);
+ {
+ var icon = (UIElement) System.Windows.Markup.XamlReader.Load(reader);
+ return icon;
+ }
}
catch (IOException)
{
diff --git a/HLab/Mvvm/Icons/html2xaml.xslt b/HLab/Mvvm/Icons/html2xaml.xslt
new file mode 100644
index 00000000..e4fda2e9
--- /dev/null
+++ b/HLab/Mvvm/Icons/html2xaml.xslt
@@ -0,0 +1,127 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/HLab/Mvvm/ViewLocator.cs b/HLab/Mvvm/ViewLocator.cs
index 590e402e..430e9f79 100644
--- a/HLab/Mvvm/ViewLocator.cs
+++ b/HLab/Mvvm/ViewLocator.cs
@@ -24,6 +24,7 @@ You should have received a copy of the GNU General Public License
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
+using System.Windows.Data;
namespace HLab.Mvvm
{
@@ -152,6 +153,14 @@ private static void OnViewModeContextChanged(DependencyObject dependencyObject,
public ViewLocator()
{
this.DataContextChanged += ViewLocator_DataContextChanged;
+
+ var b = new Binding
+ {
+ Source = this,
+ Path = new PropertyPath("DataContext"),
+ Mode = BindingMode.OneWay
+ };
+ BindingOperations.SetBinding(this, ModelProperty, b);
}
private void ViewLocator_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
@@ -159,9 +168,15 @@ private void ViewLocator_DataContextChanged(object sender, DependencyPropertyCha
//TODO : problème dans lbm mais insipensable dans erp
//if (sender is ViewLocator vl && ReferenceEquals(vl.Model, e.OldValue))
//{
- // var oldModel = vl.Model;
- // vl.Model = e.NewValue;
- // vl.Update(oldModel, vl.ViewMode, vl.ViewClass);
+ // if(vl.Model != null)
+ // { }
+
+ // if (GetBindingExpression(ModelProperty).Status == BindingStatus.Unattached)
+ // {
+ // var oldModel = vl.Model;
+ // vl.Model = e.NewValue;
+ // vl.Update(oldModel, vl.ViewMode, vl.ViewClass);
+ // }
//}
}
diff --git a/HLab/Mvvm/ViewModel.cs b/HLab/Mvvm/ViewModel.cs
index 6a67e060..2c68e502 100644
--- a/HLab/Mvvm/ViewModel.cs
+++ b/HLab/Mvvm/ViewModel.cs
@@ -25,12 +25,12 @@ You should have received a copy of the GNU General Public License
namespace HLab.Mvvm
{
- public class ViewModel : INotifyPropertyChanged
+ public class ViewModel : NotifierObject, IViewModel
{
- public event PropertyChangedEventHandler PropertyChanged
+ protected ViewModel(bool init = true) : base(init)
{
- add => this.Add(value);
- remove => this.Remove(value);
}
+
+ public T Model => this.Get();
}
}
diff --git a/HLab/Mvvm/app.config b/HLab/Mvvm/app.config
new file mode 100644
index 00000000..724d290a
--- /dev/null
+++ b/HLab/Mvvm/app.config
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/HLab/Mvvm/packages.config b/HLab/Mvvm/packages.config
new file mode 100644
index 00000000..62012005
--- /dev/null
+++ b/HLab/Mvvm/packages.config
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/HLab/Notify-4/Notifier.cs b/HLab/Notify-4/Notifier.cs
index ee11e1c0..72c1635c 100644
--- a/HLab/Notify-4/Notifier.cs
+++ b/HLab/Notify-4/Notifier.cs
@@ -22,6 +22,7 @@ You should have received a copy of the GNU General Public License
*/
using System;
using System.Collections.Concurrent;
+using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
@@ -151,6 +152,17 @@ public bool Set(object target, T value, string propertyName, Action pos
return Set(target, value, Class.GetProperty(propertyName), postUpdateAction);
}
+ public bool SetOneToMany(TNotifier target, T value, Func> getCollection, string propertyName)
+ where TNotifier : INotifierObject
+ {
+ Debug.Assert(!string.IsNullOrWhiteSpace(propertyName), "propertyName cannot be null or empty");
+
+ return Set(target, value, Class.GetProperty(propertyName), (oldValue, newValue) =>
+ {
+ if(oldValue!=null) getCollection(oldValue).Remove(target);
+ if(newValue!=null) getCollection(newValue).Add(target);
+ });
+ }
public bool Set(object target, T value, NotifierProperty property, Action postUpdateAction = null)
{
@@ -164,15 +176,9 @@ public bool Set(object target, T value, NotifierProperty property, Action();
+ var old = isnew?default(T):entry.GetValue();
- if (entry.SetValue(value))
+ if (isnew || entry.SetValue(value))
{
postUpdateAction?.Invoke(old, value);
OnPropertyChanged(new NotifierPropertyChangedEventArgs(property.Name, old, value));
@@ -201,8 +207,14 @@ public bool Update(NotifierProperty property)
return false;
}
+
+
+ private bool _subscribed = false;
public void Subscribe(INotifyPropertyChanged n)
{
+ if(_subscribed) throw new InvalidOperationException("Notifier subscribed twice");
+ _subscribed = true;
+
foreach (var method in n.GetType().GetMethods())
{
foreach (var triggedOn in method.GetCustomAttributes().OfType())
@@ -256,7 +268,5 @@ public void Subscribe(INotifyPropertyChanged n)
}
}
}
-
-
}
}
diff --git a/HLab/Notify-4/NotifierEntry.cs b/HLab/Notify-4/NotifierEntry.cs
index f96975c7..337770b4 100644
--- a/HLab/Notify-4/NotifierEntry.cs
+++ b/HLab/Notify-4/NotifierEntry.cs
@@ -39,7 +39,7 @@ public NotifierEntry(Notifier notifier, NotifierProperty property, Func