Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WP8列表框加载的MVVM_C#_Windows Phone 8_Mvvm_Listbox - Fatal编程技术网

C# WP8列表框加载的MVVM

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模式时,我可以使用自动生

我正在使用MVVM模式(Caliburn.Micro)制作一个WP8应用程序

我正在使用一个名为ProgramsList的列表框,我想在加载时执行一些操作

<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(){ }