Text zu Datei hinzufügen
Neues Buttondesign Stapelnachrichtsmodus Anpassbarer Waitlayer Eigene MessageBox
This commit is contained in:
82
ChatController/Utilities/ChatMessageFileWrapper.cs
Normal file
82
ChatController/Utilities/ChatMessageFileWrapper.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using ChatController.Annotations;
|
||||
using ChatController.Core;
|
||||
|
||||
namespace ChatController.Utilities
|
||||
{
|
||||
public class ChatMessageFileWrapper : INotifyPropertyChanged
|
||||
{
|
||||
public string FileName => !string.IsNullOrWhiteSpace(OriginalFilePath) ? Path.GetFileName(OriginalFilePath) : null;
|
||||
|
||||
private string _OriginalFilePath;
|
||||
public string OriginalFilePath
|
||||
{
|
||||
get => _OriginalFilePath;
|
||||
set
|
||||
{
|
||||
_OriginalFilePath = value;
|
||||
OnPropertyChanged(nameof(OriginalFilePath));
|
||||
OnPropertyChanged(nameof(FileName));
|
||||
}
|
||||
}
|
||||
|
||||
private string _ScaledFilePath;
|
||||
public string ScaledFilePath
|
||||
{
|
||||
get => _ScaledFilePath;
|
||||
set
|
||||
{
|
||||
_ScaledFilePath = value;
|
||||
OnPropertyChanged(nameof(ScaledFilePath));
|
||||
}
|
||||
}
|
||||
|
||||
private ImageSource _ChatMessageImageSource;
|
||||
|
||||
public ImageSource ChatMessageImageSource
|
||||
{
|
||||
get => _ChatMessageImageSource;
|
||||
private set
|
||||
{
|
||||
_ChatMessageImageSource = value;
|
||||
OnPropertyChanged(nameof(ChatMessageImageSource));
|
||||
}
|
||||
}
|
||||
|
||||
public ChatMessageFileWrapper(string originalFilePath, string scaledFilePath, string thumbnailUrl)
|
||||
{
|
||||
OriginalFilePath = originalFilePath;
|
||||
ScaledFilePath = scaledFilePath;
|
||||
|
||||
var uri = new Uri(scaledFilePath);
|
||||
|
||||
if (Constants.ImageFileExtensions.Contains(Path.GetExtension(scaledFilePath).ToUpperInvariant()) && uri.IsFile)
|
||||
{
|
||||
var bitmap = new BitmapImage(uri);
|
||||
bitmap.Freeze();
|
||||
|
||||
ChatMessageImageSource = bitmap;
|
||||
}
|
||||
else
|
||||
{
|
||||
Utils.DownloadDocumentThumbnail(thumbnailUrl, imageSource =>
|
||||
{
|
||||
ChatMessageImageSource = imageSource;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
[NotifyPropertyChangedInvocator]
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user