123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- using System;
- using System.Linq;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Input;
- using System.Windows.Threading;
- using GCHR.Model;
- namespace GCHR.View
- {
- public partial class Ampel
- {
- private readonly Button[] _buttons;
- delegate void DelAsyncWindowAction();
- public Ampel()
- {
- InitializeComponent();
- _buttons = new[] { btnStatus, btnGruen, btnGelb, btnRot };
- _anzeigeAnStatusAnpassen = delegate()
- {
- for (var i = 0; i < _buttons.Count(); i++)
- {
- _buttons[i].Visibility = (i == (int)_status) ? Visibility.Visible : Visibility.Hidden;
- }
- pbThread.Visibility = (_status == Ampelstatus.Arbeitend) ? Visibility.Visible : Visibility.Hidden;
- };
- Status = Ampelstatus.Keine;
- }
- /// <summary>
- /// Muss festgelegt werden, dass dynamisch darauf zugegriffen werden kann.
- /// </summary>
- public static DependencyProperty SourceProperty = DependencyProperty.Register(
- "Message", typeof(String), typeof(Ampel));
- /// <summary>
- /// Gibt an, ob der der Ampel zugehörige Prozess beendet ist.
- /// working und rot => false
- /// gelb und grün => true
- /// </summary>
- public bool Done
- {
- get
- {
- return (Status == Ampelstatus.Gruen || Status == Ampelstatus.Gelb);
- }
- }
- public Ampelstatus Status
- {
- get
- {
- return _status;
- }
- set
- {
- _status = value;
- Dispatcher.BeginInvoke(DispatcherPriority.Normal, _anzeigeAnStatusAnpassen);
- }
- }
- private Ampelstatus _status;
- private readonly DelAsyncWindowAction _anzeigeAnStatusAnpassen;
- public int Progress
- {
- set
- {
- DelAsyncWindowAction fortschritt = delegate
- {
- pbThread.Value = value;
- pbThread.IsIndeterminate = !(value > 0);
- };
- pbThread.Dispatcher.BeginInvoke(DispatcherPriority.Normal, fortschritt);
- if (Status == Ampelstatus.Keine)
- {
- Status = Ampelstatus.Arbeitend;
- }
- if (value == 100 && Status != Ampelstatus.Rot)
- {
- Status = (Message == "") ? Ampelstatus.Gruen : Ampelstatus.Gelb;
- }
- }
- }
- /// <summary>
- /// Benutzt <see cref="Ampel.SourceProperty"/>, um den Wert des Statustextes zu schreiben oder zu lesen.
- /// </summary>
- public string Message
- {
- get
- {
- return (String)GetValue(SourceProperty);
- }
- set
- {
- SetValue(SourceProperty, value.Trim());
- }
- }
- public void ProgressChanged(int progress, object status)
- {
- Progress = progress;
- if (status is Status)
- {
- Status = ((Status)status).Ampelstatus;
- Message = ((Status)status).Message;
- }
- else if (status is Ampelstatus)
- {
- Status = (Ampelstatus)status;
- }
- else if (status is String && !((String)status).Equals(""))
- {
- Message += (String)status + Environment.NewLine;
- }
- }
-
- private void BtnStatusClick(object sender, RoutedEventArgs e)
- {
- // MessageBox.Show(Message);
- }
- public void Reset()
- {
- Status = Ampelstatus.Keine;
- Message = "";
- }
- private void BtnStatusMouseEnter(object sender, MouseEventArgs e)
- {
- var btn = (Button)sender;
- btn.ToolTip = new ToolTip { Content = Message, StaysOpen = true };
-
- }
- }
- }
|