DashBoard update every 5sec
This commit is contained in:
@@ -14,11 +14,18 @@ namespace ProjetTheAlone.ViewModel
|
||||
{
|
||||
public class TextDefilant : BasePropriete
|
||||
{
|
||||
|
||||
public event TickHandler Tick;
|
||||
public EventArgs e = null;
|
||||
public delegate void TickHandler(object o, EventArgs e);
|
||||
|
||||
|
||||
public Timer aTimer;
|
||||
|
||||
public TextBlock textContainer;
|
||||
char[] textAfficherBuffer;
|
||||
public string TextAfficher { set { fillBuffer(value); } get { return new string(textAfficherBuffer); } }
|
||||
string textAfficher;
|
||||
public string TextAfficher { set { fillBuffer(value); textAfficher = value; } get { return new string(textAfficherBuffer); } }
|
||||
|
||||
|
||||
public TextDefilant(TextBlock tb, string text, int timeMs)
|
||||
@@ -41,6 +48,7 @@ namespace ProjetTheAlone.ViewModel
|
||||
private void OnTimedEvent(Object source, ElapsedEventArgs e)
|
||||
{
|
||||
textAfficherBuffer = RotateChar(textAfficherBuffer);
|
||||
Tick?.Invoke(this, null);
|
||||
OnPropertyChanged("TextAfficher");
|
||||
}
|
||||
|
||||
@@ -52,7 +60,7 @@ namespace ProjetTheAlone.ViewModel
|
||||
double WTB = textContainer.ActualWidth; //With of textBlock container
|
||||
double WT = MeasureString(text).Width; //With of Text
|
||||
double WS = MeasureString(" ").Width; //With of whiteSpace
|
||||
int nbSp = (int)Math.Ceiling((WTB - WT) / WS); //number of space need to fill textBlock
|
||||
int nbSp = (int)Math.Ceiling((WTB-WT) / WS); //number of space need to fill textBlock
|
||||
char[] spText = new string(' ', nbSp).ToCharArray();
|
||||
this.textAfficherBuffer = new char[nbSp + text.ToCharArray().Length];
|
||||
Array.Copy(text.ToCharArray(), 0, this.textAfficherBuffer, 0, text.Length);
|
||||
@@ -72,14 +80,19 @@ namespace ProjetTheAlone.ViewModel
|
||||
//https://stackoverflow.com/questions/9264398/how-to-calculate-wpf-textblock-width-for-its-known-font-size-and-characters
|
||||
private Size MeasureString(string candidate)
|
||||
{
|
||||
var formattedText = new FormattedText(
|
||||
candidate,
|
||||
CultureInfo.CurrentCulture,
|
||||
FlowDirection.LeftToRight,
|
||||
new Typeface(this.textContainer.FontFamily, this.textContainer.FontStyle, this.textContainer.FontWeight, this.textContainer.FontStretch),
|
||||
this.textContainer.FontSize,
|
||||
Brushes.Black,
|
||||
new NumberSubstitution(), (TextFormattingMode)1);
|
||||
FormattedText formattedText = null;
|
||||
this.textContainer.Dispatcher.Invoke(() =>
|
||||
{
|
||||
formattedText = new FormattedText(
|
||||
candidate,
|
||||
CultureInfo.CurrentCulture,
|
||||
FlowDirection.LeftToRight,
|
||||
new Typeface(this.textContainer.FontFamily, this.textContainer.FontStyle, this.textContainer.FontWeight, this.textContainer.FontStretch),
|
||||
this.textContainer.FontSize,
|
||||
Brushes.Black,
|
||||
new NumberSubstitution(), (TextFormattingMode)1);
|
||||
});
|
||||
|
||||
|
||||
return new Size(formattedText.WidthIncludingTrailingWhitespace, formattedText.Height);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace ProjetTheAlone.ViewModel
|
||||
{
|
||||
public class VM_DashBoard : TextDefilant
|
||||
{
|
||||
int tick = 0;
|
||||
public StringCollection Alerte
|
||||
{
|
||||
get
|
||||
@@ -29,6 +30,7 @@ namespace ProjetTheAlone.ViewModel
|
||||
public VM_DashBoard(TextBlock tb, string text, int timeMs) : base (tb,text, timeMs)
|
||||
{
|
||||
updateAlert();
|
||||
base.Tick += new TickHandler(onTick);
|
||||
}
|
||||
public void updateAlert()
|
||||
{
|
||||
@@ -45,5 +47,13 @@ namespace ProjetTheAlone.ViewModel
|
||||
}
|
||||
base.TextAfficher = alert;
|
||||
}
|
||||
public void onTick(object o, EventArgs e)
|
||||
{
|
||||
if(++tick > base.TextAfficher.Length)
|
||||
{
|
||||
tick = 0;
|
||||
updateAlert();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user