supermsm 2013-12-11 04:13
浏览 898

【初学提问】window phone应用开发的一个关于的绑定问题

我初学window phone的应用开发,现在想实现一个比较的功能,就是点击一个自定义的名字,然后弹出该自定义名字的相关信息,用的绑定的方法,现在遇到的问题是不知道获得绑定的那条的数据。

.cs部分代码如下:

public SetPlayer()
    {
        try
        {
            Players item0 = new Players() { name = "C罗", club = "皇家马德里", ImgUri="PlayerImg/CR.jpg" };
            Players item1 = new Players() { name = "C罗1", club = "皇家马德里21", ImgUri = "PlayerImg/CR.jpg" };
            Players item2 = new Players() { name = "C罗2", club = "皇家马德里2", ImgUri = "PlayerImg/CR.jpg" };
            Players item3 = new Players() { name = "C罗3", club = "皇家马德里3", ImgUri = "PlayerImg/CR.jpg" };
            Players item4 = new Players() { name = "C罗4", club = "皇家马德里4", ImgUri = "PlayerImg/CR.jpg" };
            Players item5 = new Players() { name = "C罗5", club = "皇家马德里5", ImgUri = "PlayerImg/CR.jpg" };
            Players item6 = new Players() { name = "C罗6", club = "皇家马德里6", ImgUri = "PlayerImg/CR.jpg" };

            Alltest.Add(item0);
            Alltest.Add(item1);
            Alltest.Add(item2);
            Alltest.Add(item3);
            Alltest.Add(item4);
            Alltest.Add(item5);
            Alltest.Add(item6);
        }
        catch (Exception e)
        {
            System.Windows.MessageBox.Show("Exception" + e.Message);
        }
    }

xaml部分代码如下:

 <ListBox x:Name="listBox" HorizontalContentAlignment="Stretch" ItemsSource="{Binding Alltest}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal" Background="Gray" Width="450" Margin="10">
                            <!--绑定Players类的ImgUri属性-->
                            <Image Width="80" Height="80" Source="{Binding ImgUri}" Stretch="Fill" x:Name="ImgPlayers"/>
                            <!--绑定Players类的name属性-->
                            <TextBlock Text="{Binding name }" FontSize="40" Width="150"  x:Name="tblName" />
                            <!--绑定Players类的club属性-->
                            <TextBlock Text="{Binding club}" FontSize="20" Width="280" x:Name="tblClub"/>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

应用部分截图如

CSDN移动问答

如我自定义了一个方法,即点击第一条,即显示相关信息,求如何获取绑定的这条信息。

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
    • ¥15 乘性高斯噪声在深度学习网络中的应用
    • ¥15 运筹学排序问题中的在线排序
    • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
    • ¥30 求一段fortran代码用IVF编译运行的结果
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛