C# WP8列表框加载的MVVM
我正在使用MVVM模式(Caliburn.Micro)制作一个WP8应用程序 我正在使用一个名为ProgramsList的列表框,我想在加载时执行一些操作C# WP8列表框加载的MVVM,c#,windows-phone-8,mvvm,listbox,C#,Windows Phone 8,Mvvm,Listbox,我正在使用MVVM模式(Caliburn.Micro)制作一个WP8应用程序 我正在使用一个名为ProgramsList的列表框,我想在加载时执行一些操作 <ListBox Name="ProgamsList" ItemsSource="{Binding ProgramsList}" HorizontalAlignment="Stretch" FontFamily="Portable User Interface" Loaded=""> 当不使用MVVM模式时,我可以使用自动生
<ListBox Name="ProgamsList" ItemsSource="{Binding ProgramsList}" HorizontalAlignment="Stretch" FontFamily="Portable User Interface" Loaded="">
当不使用MVVM模式时,我可以使用自动生成的事件处理程序
如何使用MVVM模式正确执行此操作?您可以使用命令从ViewModel中公开逻辑,然后使用行为,例如: 如果这不符合您的需要,您可以始终使用事件处理程序并从那里调用命令
xmlns:i=“clr命名空间:System.Windows.Interactivity;assembly=System.Windows.Interactivity”
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(){
}
xmlns:cmd=“clr命名空间:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras”
公共RelayCommand loaded命令
{
得到;
私人设置;
}
///
///初始化SplashScreenViewModel类的新实例。
///
公共屏幕视图模型()
{
LoadedCommand=新的RelayCommand(toDoSomehing);
}
私有void toDoSomething(){
}