Hello !
I'm trying to integrate a news ticker in my WPF project. I'm working on this one (http://www.jarloo.com/rumormill4), to work with Mvvm light without caliburn micro.I have three elements :
-Ticker Windows (the main windows) - TickerWindow
-Ticker Layout (userview for buttons) - TickerLayout
-Ticker Item (for the animated text which takes places in a canvas on ticker layout view ) - TickerNormalView
Ticker Windows (this on show up after a timer tick event)
<Window x:Class="TerminalClient_Mvvmlight.Views.Ticker.TickerWindow" 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" xmlns:ignore="http://www.ignore.com" xmlns:Views="clr-namespace:TerminalClient_Mvvmlight.Views.Ticker" xmlns:vm="clr-namespace:TerminalClient_Mvvmlight.ViewModel" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:command="http://www.galasoft.ch/mvvmlight" mc:Ignorable="d ignore" WindowStyle="None" Height="44.949" Width="931.35" DataContext="{Binding TickerWindowsVM, Source={StaticResource Locator}}"><i:Interaction.Triggers><i:EventTrigger EventName="Loaded"><command:EventToCommand Command="{Binding FirstViewCommand}"/></i:EventTrigger></i:Interaction.Triggers><Grid><ContentControl Content="{Binding CurrentViewModel}" /></Grid></Window>
My ContentControl load my TickerLayout view
<UserControl x:Class="TerminalClient_Mvvmlight.Views.Ticker.TickerLayout" 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" xmlns:tb="http://www.hardcodet.net/taskbar" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:command="http://www.galasoft.ch/mvvmlight" xmlns:ignore="http://www.ignore.com" xmlns:Views="clr-namespace:TerminalClient_Mvvmlight.Views.Ticker" mc:Ignorable="d ignore" Height="38" Width="900" DataContext="{Binding TickerLayoutVM, Source={StaticResource Locator}}"><Canvas x:Name="LayoutRoot"><Button Content="X" Canvas.Left="873" Canvas.Top="10" Width="17"/></Canvas></UserControl>
And my problem is here... I'm trying to found a solution to access to the canvas "LayoutRoot" for instanciate my Ticker in it.
My TickerLayoutViewModel
public class TickerLayoutViewModel : ViewModelBase { private Ticker<TickerNormalView> ticker; private readonly FeedManager manager = new FeedManager(); public ICommand TickerLoadCommand { get; private set; } public TickerLayoutViewModel() { //CurrentViewModel = TickerViewModel._firstViewModel; manager.NewFeedItem += (o, e) => Execute.BeginOnUIThread(() => AddItem(e.Item)); TickerLoadCommand = new RelayCommand(() => LoadTicker()); } private void AddItem(FeedItem itm) { ticker.Items.Enqueue(new TickerNormalView(itm)); } private void LoadTicker() { MessageBox.Show("TickerLayout load !"); ticker = new Ticker<TickerNormalView>(new TickerLayout().LayoutRoot); ticker.Speed = new TimeSpan(0, 1, 0); manager.Start(); ticker.Start(); } }
I'm searching how to synchronise this code line :
ticker = new Ticker<TickerNormalView>(new TickerLayout().LayoutRoot);
With the instance of my TickerLayout view opened in my window.
I'm very lost... so could you give an example ? or a better solution ?
Thanks for any help