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 想问一下stata17中这段代码哪里有问题呀
    • ¥15 flink cdc无法实时同步mysql数据
    • ¥100 有人会搭建GPT-J-6B框架吗?有偿
    • ¥15 求差集那个函数有问题,有无佬可以解决
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决