从Listview Windows Phone 8.1上的一个选项中获取4个项目

时间:2015-09-01 08:38:52

标签: c# listview windows-phone-8.1

我有一个问题,我有一个列表View可以称之为ListView1,它是从Azure同步后从本地存储动态填充的。

现在我在选择并从项目点击中获取信息时遇到问题 我需要获取四种不同类型的信息,并在列表视图中有项目点击时将其传递给弹出窗口。

//This is the way the List is Created
string DB_PATH = Path.Combine(ApplicationData.Current.LocalFolder.Path, "my.db");

    public async void CreateList ()
    {
        await AzureWebService.Instance.InitLocalStoreAsync(DB_PATH);
        var t = await AzureWebService.Instance.GetListItems(); //GET THE OG LIST

        var list = new ObservableCollection<winMerchant>(); //create a new list of Names, (with the BitmapImage Field )

        foreach (var f in t)
        {
            var m = new winDirectory(); //give the customized merchant object, the same VALUES as the ACTUAL mercahnt object

            m.MyName1 = f.MyName1;
            m.MyName2 = f.MyName2;
            m.MyNumber = f.MyNumber; //int 
            m.MyPic = ImageHelper.Base64StringToBitmap(f.MyPic); //CUSTOM PART ==> Take the newly defined BitmapImage (wMyPic) and convert the Pic string into it

            list.Add(m); //add the new People into a list

        }
        MyList.ItemsSource = list;         
    }

这就是xaml

<ListView.ItemTemplate>
    <DataTemplate>

        <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Stretch">

            <Image Source="{Binding wPic}" Width="75" Height="75" />

            <StackPanel Orientation="Vertical" VerticalAlignment="Center">

                <TextBlock Text="{Binding wMyName1}" />
                <TextBlock Text="{Binding wMyName2}" />

            </StackPanel>
        </StackPanel>

    </DataTemplate>
</ListView.ItemTemplate>

助手类

class winMerchant: Contacts
{
    public   BitmapImage wPic { get; set; }

    public int wMyNumber { get; set; }

    public string wMyName1 { get; set; }

    public string wMyName2 { get; set; }
}

点击时应将数字传递给弹出窗口... 任何帮助都感激不尽!

2 个答案:

答案 0 :(得分:0)

尝试添加

AutomationProperties.Name="{Binding wMyNumber}" to the <Image>

通过这个你可以传递被点击的对象的数量,在c#(点击事件内)你可以创建一个List&lt;&gt;或者包含有关对象数据的数组(这样您就可以使用此对象集合在弹出按钮中显示它)

答案 1 :(得分:0)

您可以从ListView的项目点击事件中获取所选项目的编号。

private void MainListView_ItemClick(object sender, ItemClickEventArgs e)
    {
        var item = e.ClickedItem as winMerchant;
        int number = item.wMyNumber;
    }

同时使ListView的IsItemClickEnabled =“True”。