当前位置:编程学习 > wap >>

【初学提问】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>


应用部分截图如下


例如我自定义了一个方法,即点击第一条,即显示相关信息,求如何获取绑定的这条信息。 --------------------编程问答-------------------- --------------------编程问答-------------------- listbox.selecteditem as players,这样就行了
补充:移动开发 ,  Windows Phone
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,