[英]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.