zoukankan      html  css  js  c++  java
  • 在WindowsPhone8中生成基于MVVM Light的LongListSelector命令绑定

    继续《在WindowsPhone8中生成基于MVVM Light的LongListSelector拼音检索绑定》一文,项目不再引用上一个项目,但功能实现相同,我们已经对数据作了绑定,下面要携带参数传值导航至具体内容页:

    1.在引用中添加

        xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
        xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WP71"
    

     2.绑定命令:我实现的功能为:单机LongListSelector的某个项(此例中为文本框),跳转至相应页面(ContentPage)内容页

    <phone:LongListSelector
                       x:Name="MountainIndexLLS"
                       JumpListStyle="{StaticResource AddrBookJumpListStyle}"
                       Background="Transparent"
                       GroupHeaderTemplate="{StaticResource AddrBookGroupHeaderTemplate}"        
                       LayoutMode="List"
                       IsGroupingEnabled="true"
                       HideEmptyGroups ="true" ItemsSource="{Binding DataSource}">
                        <phone:LongListSelector.ItemTemplate>
                            <DataTemplate>
                                <StackPanel VerticalAlignment="Top">
                                    <TextBlock FontWeight="Bold"  Text="{Binding Name}" Style="{StaticResource PhoneTextLargeStyle}" FontFamily="{StaticResource PhoneFontFamilySemiBold}" Foreground="White"/>
                                    <TextBlock Text="{Binding Region}" Style="{StaticResource PhoneTextNormalStyle}" TextWrapping="Wrap" FontFamily="{StaticResource PhoneFontFamilySemiBold}" Foreground="Gray"/>
                                </StackPanel>
                            </DataTemplate>  
                        </phone:LongListSelector.ItemTemplate>
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="Tap">
                                <cmd:EventToCommand Command="{Binding TapCommand}" CommandParameter="{Binding SelectedItem,ElementName=MountainIndexLLS}"/>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </phone:LongListSelector>
    

     在这里,我们将上例中的LongListSelector中LongListSelector.ItemTemplate的样式代码由PhoneApplicationPage.Resources中转移到了LongListSelector中,在这里,每一个LongListSelector项均被绑定了一个TapCommand的命令,下面,我们在MainViewModel中完成这条命令,实现我们需要的功能。

    3.写命令代码:(MainViewModel)

    public RelayCommand<MountainIndex> TapCommand { get; private set; }
            public void NavigationTap(MountainIndex mouIndex)
            {
                System.Windows.MessageBox.Show(mouIndex.Name+mouIndex.Region);
            }
    

     我们先不实现导航,仅仅是取得文本框的内容

    public MainViewModel()
            {
                TapCommand = new RelayCommand<MountainIndex>((mouIndex) => NavigationTap(mouIndex));
            }
    

     实现结果如下:

  • 相关阅读:
    部署第二个master节点
    Spark On YARN使用时上传jar包过多导致磁盘空间不够。。。
    Spark1.3使用外部数据源时条件过滤只要是字符串类型的值均报错
    spark1.3编译过程中遇到的一个坑
    Hive On Spark hiveserver2方式使用
    Hive On Spark概述
    Hive On Spark环境搭建
    RDD常用方法之subtract&intersection&cartesian
    SparkSQL DataFrames操作
    通过Spark SQL关联查询两个HDFS上的文件操作
  • 原文地址:https://www.cnblogs.com/valentineisme/p/3088114.html
Copyright © 2011-2022 走看看