Note that there are some explanatory texts on larger screens.

plurals
  1. POWpf c# ticker rss news reader
    primarykey
    data
    text
    <p>I'm making an application for wpf C# in expression blend 4. I have followed RumorMills tutorial over at <a href="http://www.jarloo.com/rumormill4/" rel="nofollow">http://www.jarloo.com/rumormill4/</a></p> <p>However he doesn't provide a full tutorial, so i have taken som of his code trying to implement it into my own "home media center" application for testing. I have sorted out 90% of the errors, just one remaining - i hope it doesn't come any additional ones... You could find any additional code not included in the question over at his post. See my code below:</p> <p>Main code file for the screen hosting the news ticker</p> <pre><code>using System; using System.Collections.Generic; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.Windows.Media.Animation; using Microsoft.Expression.Controls; using MySoftware_Inspire.Feed; using System.ComponentModel; namespace blablabla { /// &lt;summary&gt; /// Interaction logic for MainWindow.xaml /// &lt;/summary&gt; public partial class MainWindow : Window { List&lt;string&gt; weatherwords = new List&lt;string&gt; {"weather", "in", "umbrella", "rain", "sun", "sunny", "overcast", "forecast", "cloudy"}; List&lt;string&gt; mathwords = new List&lt;string&gt; {"+", "-", "*", "/", ":"}; String searchInput; System.Windows.Threading.DispatcherTimer dispatcherTimer; private readonly FeedManager manager = new FeedManager(); private readonly Ticker&lt;TickerItem&gt; ticker; private delegate void FeedDelegate(FeedItem itm); //would be better to detect the height of the titlebar //and window chrome instead of hardcoding this. private const int FULL_HEIGHT = 75; private const int SHORT_HEIGHT = 55; private int height = FULL_HEIGHT; public MainWindow() { this.InitializeComponent(); Width = SystemParameters.PrimaryScreenWidth; ticker = new Ticker&lt;TickerItem&gt;(LayoutRoot) {Speed = new TimeSpan(0, 2, 0)}; ticker.ItemDisplayed += ticker_ItemDisplayed; manager.NewFeedItem += manager_NewFeedItem; // Insert code required on object creation below this point. } private void ticker_ItemDisplayed(object sender, ItemEventArgs&lt;TickerItem&gt; e) { txtItems.Text = ticker.Items.Count.ToString(); manager.MarkFeedAsRead(e.Item.FeedItem); } private void manager_NewFeedItem(object sender, ItemEventArgs&lt;FeedItem&gt; e) { //Got a new article. Marshall to the UI thread Dispatcher.Invoke(DispatcherPriority.Background, new FeedDelegate(AddItem), e.Item); } private void AddItem(FeedItem itm) { lock (this) { ticker.Items.Enqueue(new TickerItem(itm)); txtItems.Text = ticker.Items.Count.ToString(); } } private void homequicktip_DoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e) { //Doubleclicked to homequicktip notification DoubleAnimation fadeouthomequicktip = new DoubleAnimation(); fadeouthomequicktip.From = 1; fadeouthomequicktip.To = 0.0; fadeouthomequicktip.Duration = new Duration(TimeSpan.FromSeconds(1)); //Play fade out animation on homequicktip homequicktip.BeginAnimation(Callout.OpacityProperty, fadeouthomequicktip); } private void MainWindow_Activated(object sender, System.EventArgs e) { //Start feed manager manager.Start(); //Load up clock and play startup animations dispatcherTimer = new System.Windows.Threading.DispatcherTimer(); dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick); dispatcherTimer.Interval = new TimeSpan(0,0,1); dispatcherTimer.Start(); //Rotate arcs for nice effect //Arc 1 rotation DoubleAnimation arcrotateAnim1 = new DoubleAnimation(); arcrotateAnim1.From = -70; arcrotateAnim1.To = -3600; arcrotateAnim1.AutoReverse = true; arcrotateAnim1.Duration = new Duration(TimeSpan.FromSeconds(30)); arcrotateAnim1.RepeatBehavior = RepeatBehavior.Forever; arc1.RenderTransformOrigin = new Point(0.5, 0.5); RotateTransform rt = new RotateTransform(); arc1.RenderTransform = rt; rt.BeginAnimation(RotateTransform.AngleProperty, arcrotateAnim1); //Arc 2 rotation DoubleAnimation arcrotateAnim2 = new DoubleAnimation(); arcrotateAnim2.From = 90; arcrotateAnim2.To = 3690; arcrotateAnim2.AutoReverse = true; arcrotateAnim2.Duration = new Duration(TimeSpan.FromSeconds(30)); arcrotateAnim2.RepeatBehavior = RepeatBehavior.Forever; arc1.RenderTransformOrigin = new Point(0.5, 0.5); RotateTransform rt2 = new RotateTransform(); arc2.RenderTransform = rt2; rt2.BeginAnimation(RotateTransform.AngleProperty, arcrotateAnim2); } private void Window_Closing(object sender, CancelEventArgs e) { manager.Stop(); manager.SaveReadFeeds(); } private void Window_SizeChanged(object sender, SizeChangedEventArgs e) { if (e.HeightChanged) { if (e.NewSize.Height != height) Height = height; } } private void btnLock_MouseUp(object sender, MouseButtonEventArgs e) { if (WindowStyle == WindowStyle.None) { WindowStyle = WindowStyle.ToolWindow; height = FULL_HEIGHT; Height = height; } else { WindowStyle = WindowStyle.None; height = SHORT_HEIGHT; Height = height; } } private void btnStop_MouseUp(object sender, MouseButtonEventArgs e) { btnStop.Visibility = Visibility.Collapsed; btnGo.Visibility = Visibility.Visible; ticker.Stop(); } private void btnGo_MouseUp(object sender, MouseButtonEventArgs e) { btnStop.Visibility = Visibility.Visible; btnGo.Visibility = Visibility.Collapsed; ticker.Start(); } private void dispatcherTimer_Tick(object sender, EventArgs e) { //Updating clock timeLabel.Content = DateTime.Now.ToString(); dispatcherTimer.Start(); } private void searchTextbox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e) { if (e.Key == System.Windows.Input.Key.Enter) { //Enter key was pressed - begin search //Create instance of SearchWindow SearchWindow SearchWindow = new SearchWindow(); //Memorize current text in TextBox so it doesn't look like we've changed anything searchInput = searchTextBox.Text; //Pressed enter on searchTextBox if (searchTextBox.Text.Contains(" ")) { //Search input contains spaces which needs to be removed before search can happen searchTextBox.Text.Replace(" ", "+"); } //Open search SearchWindow.searchBrowser.Navigate("http://www.wolframalpha.com/input/?i=" + searchTextBox.Text); SearchWindow.Show(); } } } } </code></pre> <p>TickerItem.xaml:</p> <pre><code>&lt;UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="Jarloo.RumorMill4.TickerItem" x:Name="UserControl" d:DesignWidth="640" d:DesignHeight="480" Height="39"&gt; &lt;Grid Height="39" &gt; &lt;TextBlock x:Name="PART_TextBlock" Foreground="#FFFFFFFF" Height="18" VerticalAlignment="Top" TextWrapping="NoWrap"&gt; &lt;Hyperlink x:Name="hlLink" RequestNavigate="hpLink_RequestNavigate"&gt; &lt;TextBlock x:Name="txtTitle" Foreground="#FFFFFFFF" TextWrapping="NoWrap"&gt;&lt;/TextBlock&gt; &lt;/Hyperlink&gt; &lt;/TextBlock&gt; &lt;TextBlock x:Name="txtDate" Margin="0,12,0,1" Foreground="#FF939393" TextWrapping="NoWrap" FontSize="10"/&gt; &lt;TextBlock x:Name="txtSource" Margin="0,20,0,1" Foreground="#FFD47432" TextWrapping="NoWrap" FontSize="10" /&gt; &lt;/Grid&gt; &lt;/UserControl&gt; </code></pre> <p>TickerItem.xaml.cs:</p> <pre><code>using System; using System.Diagnostics; using System.Windows.Controls; using System.Windows.Navigation; using blablablabla.Feed; namespace blablablabla { public partial class TickerItem { public TickerItem(FeedItem item) { InitializeComponent(); FeedItem = item; txtDate.Text = item.PubDate; txtTitle.Text = item.Title; if (item.Link.ToLower().StartsWith("http")) { try { hlLink.NavigateUri = new Uri(item.Link); } catch { } } txtSource.Text = item.Source; } public FeedItem FeedItem { get; private set;} public string PubDate { get { TextBlock date = (TextBlock)FindName("txtDate"); return date.Text; } } public string Title { get { return txtTitle.Text; } } public string Url { get { return hlLink.NavigateUri.ToString(); } } public string Source { get { return txtSource.Text; } } private void hpLink_RequestNavigate(object sender, RequestNavigateEventArgs e) { Process.Start(new ProcessStartInfo(e.Uri.ToString())); } } } </code></pre> <p>Ticker.cs:</p> <pre><code>using System; using System.Collections.Generic; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Threading; namespace blablablabla { public class Ticker&lt;T&gt; where T : FrameworkElement { private readonly DispatcherTimer displayTimer = new DispatcherTimer(); public EventHandler&lt;ItemEventArgs&lt;T&gt;&gt; ItemDisplayed; public bool Running { get; set; } public double SeperatorSize { get; set; } public TimeSpan Speed { get; set; } public Queue&lt;T&gt; Items { get; set; } public Panel Container { get; private set; } public void Stop() { displayTimer.Stop(); Running = false; } public void Start() { displayTimer.Start(); displayTimer.Interval = new TimeSpan(0,0,0,1); Running = true; } public Ticker(Panel container) { SeperatorSize = 25; Container = container; Container.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); Container.Arrange(new Rect(Container.DesiredSize)); Speed = new TimeSpan(0, 0, 0, 40); Items = new Queue&lt;T&gt;(); displayTimer.Tick += displayTimer_Tick; displayTimer.Start(); Running = true; } private void displayTimer_Tick(object sender, EventArgs e) { DisplayNextItem(); } private void DisplayNextItem() { if (Items.Count == 0) return; T item = Items.Dequeue(); Container.Children.Add(item); AnimateMove(item); if (ItemDisplayed != null) ItemDisplayed(this, new ItemEventArgs&lt;T&gt;(item)); } private void AnimateMove(FrameworkElement e) { const double to = -500; e.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); e.Arrange(new Rect(e.DesiredSize)); double from = Container.ActualWidth; int unitsPerSec = Convert.ToInt32(Math.Abs(from - to)/Speed.TotalSeconds); int nextFire = Convert.ToInt32((e.ActualWidth + SeperatorSize)/unitsPerSec); displayTimer.Stop(); displayTimer.Interval = new TimeSpan(0, 0, nextFire); displayTimer.Start(); TaggedDoubleAnimation ani = new TaggedDoubleAnimation { From = from, To = to, Duration = new Duration(Speed), TargetElement = e }; ani.Completed += ani_Completed; TranslateTransform trans = new TranslateTransform(); e.RenderTransform = trans; trans.BeginAnimation(TranslateTransform.XProperty, ani, HandoffBehavior.Compose); } private void ani_Completed(object sender, EventArgs e) { Clock clock = (Clock) sender; TaggedDoubleAnimation ani = (TaggedDoubleAnimation) clock.Timeline; FrameworkElement element = ani.TargetElement; Container.Children.Remove(element); } } } </code></pre> <p>The error is as follows - it may not be 100% properly translated because i'm norwegian and the error was printed out in norwegian. Have a look:</p> <p>Error:</p> <p>The type blablablabla.TickerItem cannot be used as the type parameter T in the generic type or method blablablabla.Ticker. It does not exist any implicit reference-convertion from blablablabla.TickerItem to System.Windows.FrameworkElement</p> <p>Do any of you guys know what this means?</p> <p>I'm REALLY stuck here, please help! Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload