|
@@ -12,34 +12,34 @@ using System.Windows.Controls;
|
|
|
using System.Windows.Media;
|
|
|
using System.Windows.Media.Imaging;
|
|
|
|
|
|
-namespace InABox.DynamicGrid
|
|
|
+namespace InABox.DynamicGrid;
|
|
|
+
|
|
|
+public class DFImageControl : DynamicFormControl<DFLayoutImage>
|
|
|
{
|
|
|
- public class DFImageControl : DynamicFormControl<DFLayoutImage>
|
|
|
+ private static readonly Dictionary<Guid, BitmapImage?> images = new();
|
|
|
+ protected override FrameworkElement Create()
|
|
|
{
|
|
|
- private static readonly Dictionary<Guid, BitmapImage> images = new();
|
|
|
- protected override FrameworkElement Create()
|
|
|
+ var image = new Image();
|
|
|
+ if (Control.Image.IsValid())
|
|
|
{
|
|
|
- var image = new Image();
|
|
|
- if (Control.Image.IsValid())
|
|
|
+ if (images.TryGetValue(Control.Image.ID, out var bitmapImage))
|
|
|
{
|
|
|
- if (images.ContainsKey(Control.Image.ID)) image.Source = images[Control.Image.ID];
|
|
|
- new Client<Document>().Query(
|
|
|
- new Filter<Document>(x => x.ID).IsEqualTo(Control.Image.ID),
|
|
|
- new Columns<Document>(x => x.ID, x => x.Data),
|
|
|
- null,
|
|
|
- (data, error) =>
|
|
|
- {
|
|
|
- var bytes = data?.Rows.FirstOrDefault()?.Get<Document, byte[]>(x => x.Data);
|
|
|
- var source = new BitmapImage();
|
|
|
- source.LoadImage(bytes);
|
|
|
- images[Control.Image.ID] = source;
|
|
|
- Dispatcher.Invoke(() => { image.Source = source; });
|
|
|
- }
|
|
|
- );
|
|
|
+ image.Source = bitmapImage;
|
|
|
}
|
|
|
-
|
|
|
- image.Stretch = Stretch.Uniform;
|
|
|
- return image;
|
|
|
+ new Client<Document>().Query(
|
|
|
+ new Filter<Document>(x => x.ID).IsEqualTo(Control.Image.ID),
|
|
|
+ new Columns<Document>(x => x.ID, x => x.Data),
|
|
|
+ null,
|
|
|
+ (data, error) =>
|
|
|
+ {
|
|
|
+ var source = ImageUtils.LoadImage(data?.Rows.FirstOrDefault()?.Get<Document, byte[]>(x => x.Data));
|
|
|
+ images[Control.Image.ID] = source;
|
|
|
+ Dispatcher.Invoke(() => { image.Source = source; });
|
|
|
+ }
|
|
|
+ );
|
|
|
}
|
|
|
+
|
|
|
+ image.Stretch = Stretch.Uniform;
|
|
|
+ return image;
|
|
|
}
|
|
|
}
|