在viewmodel Mvvm light / wpf中获取视图实例

时间:2015-04-23 12:27:31

标签: c# wpf mvvm

我有一个窗口视图,我希望在其中放置一个Ticker View

<Window x:Class="TerminalClient_Mvvmlight.Views.Ticker.TickerView"
        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:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:command="http://www.galasoft.ch/mvvmlight"
        mc:Ignorable="d ignore"
        DataContext="{Binding TickerVM, Source={StaticResource Locator}}" WindowStyle="None" Height="44.949" Width="931.35">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Loaded">
            <command:EventToCommand Command="{Binding TickerWindowLoaded}"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>
    <Grid>
        <Views:TickerLayout  Grid.Column="0"/>
    </Grid>
</Window>

我正在尝试获取“TickerLayout”的实例,因为我需要它作为我的Ticker的布局,在我的viewmodel中

private void OnTickerWindowLoaded()
{
    MessageBox.Show("TickerView chargé !");
    var v = (TickerLayout)this();
    ticker = new Ticker<TickerNormalView>(new TickerLayout().LayoutRoot);
    ticker.Speed = new TimeSpan(0, 1, 0);
    manager.Start();
    ticker.Start();
}

我希望在事件发生后打开这个TickerLayout实例时,将“TickerLayout()”与TickerLayout实例同步。你能帮帮我吗?

0 个答案:

没有答案