Hallo Community,
vielleicht hat einer von Euch eine Idee.
Ich baue gerade einen kleinen Datenbankbasierten LiveTicker, welcher Texte aus eben dieser anzeigt. Die Texte laufen als eine Art "N24 Newsticker" über den Bildschirm.
Alles funktioniert, nur habe ich noch eine Unschönheit.
Der Text läuft links erst komplett aus dem Bild, bevor er rechts erneut erscheint.
Es soll aber so sein, dass der Text Anfang erneut zu sehen ist, auch wenn der Text links noch nicht ganz rausgelaufen ist.
Es soll also der Ticker nie leer sein, sondern mit einem gewissen Abstand durchlaufen.
Leider habe ich keinerlei Idee dazu, außer einen zweiten doubleanimation- Ticker an derselben Position zu programmieren.
Nur hat das zur Folge, dass der zweite Ticker zwar später startet, aber beide enden gleichzeitig, d.h. der zweite überholt den ersten 😃
#region SQL
using (DataClasses1DataContext con = new DataClasses1DataContext())
{
IEnumerable<string> text = from t in con.TRNewsticker where t.bereich1 == "1" select t.meldung;
//for (int i = text.Count()-1; i >=0; i--)
//{
// TickerText += " +++ " + text.ElementAt(i);
//}
//TickerText += " +++ ";
foreach (string item in text)
{
TickerText += " +++++ " + item.ToString();
}
TickerText += " +++++ ";
tbmarquee.Text = TickerText;
tbmarquee1.Text = TickerText;
}
#endregion
Rect desktopWorkingArea = System.Windows.SystemParameters.WorkArea;
//This = Window1
//this.Left = desktopWorkingArea.Right - this.Width;
this.Top = desktopWorkingArea.Bottom-this.Height;//1560-50
this.Width = desktopWorkingArea.Width -10; //2560-10, weil this.Left = 5
this.Left = 5;
//Mit Faktor
if (dFaktor != 1.0)
{
this.Height *= dFaktor;
tbmarquee.FontSize *= dFaktor;
tbmarquee1.FontSize *= dFaktor;
this.Top = desktopWorkingArea.Bottom - (this.Height);//1560-50
this.Width = desktopWorkingArea.Width - 10; //2560-10, weil this.Left = 5
}
#region Erster Ticker
doubleAnimation.From = -tbmarquee.Width;// +Convert.ToDouble(offset);
doubleAnimation.To = canMain.ActualWidth;
doubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
doubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(ToDouble(dur, false)));
clock = doubleAnimation.CreateClock();
tbmarquee.ApplyAnimationClock(Canvas.RightProperty, clock);
#endregion
#region Zweiter Ticker
doubleAnimationRepeat.From = (-tbmarquee1.Width * 2)-1000;// + Convert.ToDouble(offset);
doubleAnimationRepeat.To = canMain.ActualWidth;
//doubleAnimationRepeat.BeginTime = TimeSpan.FromSeconds(ToDouble(dur, false));
// doubleAnimationRepeat.By = ToDouble(dur, false);
doubleAnimationRepeat.RepeatBehavior = RepeatBehavior.Forever;
doubleAnimationRepeat.Duration = new Duration(TimeSpan.FromSeconds(ToDouble(dur, false)));
clockRepeat = doubleAnimationRepeat.CreateClock();
tbmarquee1.ApplyAnimationClock(Canvas.RightProperty, clockRepeat);
#endregion
Und der XAML:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Background="Wheat"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Name="KNOLL_LiveTicker" x:Class="Marquee.Window1"
Title="KNOLL LiveTicker" WindowStartupLocation="Manual" Loaded="Window_Loaded" ResizeMode="NoResize" Topmost="True" Cursor="Hand" Height="50" Opacity="0.8" WindowStyle="None" HorizontalAlignment="Left" VerticalAlignment="Bottom" d:DesignWidth="1025" ShowInTaskbar="False">
<Canvas Canvas.Left="29" x:Name="canMain" Background="Wheat" Panel.ZIndex="100" RenderTransformOrigin="0.495,0.099" Height="0" VerticalAlignment="Top" >
<TextBlock Margin="0" FontSize="36" x:Name="tbmarquee1" Opacity="0.8" MouseDown="tbmarquee1_MouseDown" MouseUp="tbmarquee1_MouseUp" Background="Transparent" Width="{Binding Path=ActualWidth, ElementName=tbmarquee1}">
<TextBlock.Effect>
<DropShadowEffect Opacity="0.5" ShadowDepth="2"/>
</TextBlock.Effect><Run Text=""/></TextBlock>
<TextBlock Margin="0" FontSize="36" x:Name="tbmarquee" Opacity="0.8" MouseDown="tbmarquee_MouseDown" MouseUp="tbmarquee_MouseUp" Background="Transparent" Width="{Binding Path=ActualWidth, ElementName=tbmarquee}">
<TextBlock.Effect>
<DropShadowEffect Opacity="0.5" ShadowDepth="2"/>
</TextBlock.Effect><Run Text=""/></TextBlock>
</Canvas>
</Window>
Bitte benutze die richtigen Code-Tags. XAML ist kein C#-Code. [Hinweis] Wie poste ich richtig? Punkt 6
Wäre das alles via [Artikel] Drei-Schichten-Architektur und ner ordentlichen Umsetzung via MVVM Pattern, wie es für WPF gedacht ist, nicht um Welten einfacher und besser?
- performance is a feature -
Microsoft MVP - @Website - @AzureStuttgart - github.com/BenjaminAbt - Sustainable Code