[英]WP8 Listbox Loaded MVVM
我正在使用MVVM模式(Caliburn.Micro)制作WP8应用程序。
我正在使用一个名为ProgramsList的列表框,并且想在加载时做一些事情。
<ListBox Name="ProgamsList" ItemsSource="{Binding ProgramsList}" HorizontalAlignment="Stretch" FontFamily="Portable User Interface" Loaded="">
当不使用MVVM模式时,可以使用自动生成的事件处理程序。
如何使用MVVM模式正确执行此操作?
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras"
<ListBox Name="ProgamsList" ItemsSource="{Binding ProgramsList}" HorizontalAlignment="Stretch" FontFamily="Portable User Interface" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<cmd:EventToCommand Command="{Binding LoadedCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ListBox>
public RelayCommand LoadedCommand
{
get;
private set;
}
/// <summary>
/// Initializes a new instance of the SplashScreenViewModel class.
/// </summary>
public SplashScreenViewModel()
{
LoadedCommand = new RelayCommand(toDoSomehing);
}
private void toDoSomething(){
}
您可以使用命令从ViewModel公开逻辑,然后使用行为,例如: http : //metroeventtocommand.codeplex.com/
如果这不符合您的需求,则可以始终使用事件处理程序并从那里调用命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.