laatzen/Common/Ui.ProductionControls/ctlPictureProgress.xaml.cs
2021-10-01 11:09:20 +02:00

131 lines
3.2 KiB
C#

using System;
using System.ComponentModel;
using System.Windows.Controls;
using System.Windows.Media;
using Ui.ProductionControls.Enums;
using static Ui.ProductionControls.ctlPictureProgressBar;
namespace Ui.ProductionControls
{
public class PictureProgressModel : INotifyPropertyChanged
{
protected virtual void NotifyPropertyChanged(String propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public event PropertyChangedEventHandler PropertyChanged;
private Img currentImg = Img.Default;
public Img CurrentImg
{
get { return currentImg; }
set
{
currentImg = value;
Text = Converter.ImgToImage.GetText(currentImg);
ImageSource = Converter.ImgToImage.GetImagePath(currentImg);
}
}
private ImgStatus currentState = ImgStatus.Init;
public ImgStatus CurrentState
{
get { return currentState; }
set
{
currentState = value;
Color = Converter.ImgStatusToColor.GetBrush(currentState);
}
}
public string Headline
{
get
{
if (Text.Length > 27)
{
return Text.Substring(0, 27) + "...";
}
return Text;
}
private set
{
text = value;
}
}
private string text;
public string Text
{
get { return text; }
set
{
text = value;
NotifyPropertyChanged(nameof(Text));
NotifyPropertyChanged(nameof(Headline));
}
}
private Brush color;
public Brush Color
{
get { return color; }
set
{
color = value;
NotifyPropertyChanged(nameof(Color));
}
}
//private Img image;
//private ImgStatus state;
//private string name;
private ctlPictureProgressBar.ImageElement imageEle;
public PictureProgressModel(ctlPictureProgressBar.ImageElement addImageEle)
{
imageEle = addImageEle;
imageEle.OnChanged += ImageEle_OnChanged;
}
private void ImageEle_OnChanged(object sender, EventArgs e)
{
if (sender is ImageElement ele)
{
CurrentImg = ele.Image;
CurrentState = ele.State;
Text = ele.Name;
}
}
private string imageSource;
public string ImageSource
{
get { return imageSource; }
set
{
imageSource = value;
NotifyPropertyChanged(nameof(ImageSource));
}
}
}
public partial class ctlPictureProgress : UserControl
{
private PictureProgressModel ViewModel = null;
public ctlPictureProgress(PictureProgressModel mdl)
{
InitializeComponent();
ViewModel = mdl;
DataContext = ViewModel;
}
}
}