【问题标题】:Get 4 Items from one Selection on Listview Windows Phone 8.1在 Listview Windows Phone 8.1 上从一个选择中获取 4 个项目
【发布时间】:2015-09-01 08:38:52
【问题描述】:

我有一个问题,我有一个列表视图,我们称之为 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; }
}

数字应在点击时传递给浮出控件... 任何帮助都感激不尽!

【问题讨论】:

    标签: c# listview windows-phone-8.1


    【解决方案1】:

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

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

    还要让 Listview 的 IsItemClickEnabled="True"。

    【讨论】:

      【解决方案2】:

      尝试添加

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

      有了这个你可以传递被点击对象的数量,在c#中(在点击事件中)你可以创建一个List或者一个包含你的对象数据的数组(这样你就可以使用这个对象集合来在弹出窗口中显示)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-07-04
        • 2015-07-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多