简体   繁体   English

如何选择Windows Phone 8.1下拉所选项目

[英]how to select windows Phone 8.1 Dropdown selected item

In XAML 在XAML中

<ComboBox x:Name="CmbVendor" Style="{StaticResource ComboBoxStyle}" SelectedValue="{Binding vendor_name}"  >
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <ComboBoxItem x:Name="text"  Content="{Binding vendor_name}"/>
        </DataTemplate>
   </ComboBox.ItemTemplate>
   <!--
   <ComboBoxItem Content="15 minutes" Tag="15"  />
   <ComboBoxItem Content="30 minutes" Tag="30"  />
   <ComboBoxItem Content="1 hour" Tag="60"  />
   <ComboBoxItem Content="1 day" Tag="1440"  />
   -->   
</ComboBox>

when I use static combo-box item I am getting data using the method 当我使用静态组合框项目时,我正在使用方法获取数据

string Title = ((ComboBoxItem)CmbVendor.SelectedItem).Content.ToString();

but when I change to dynamic I am not getting selected item. 但是当我更改为动态时,没有得到选择的项目。

What is the solution? 解决办法是什么?

Note In c# I called getdropdownvalue() in constructor 注意在C#中我在构造函数中调用了getdropdownvalue()

private async void getdropdownvalue()
{
    ........
    CmbVendor.ItemsSource = items;    
}

If the code you've added to populate the Combobox is something along the lines of: 如果您添加的用于填充组合框的代码类似于以下内容:

List<VendorNames> vender_name = new List<VendorNames>();
vender_names .Add(new VendorNames() { Name = "NAMEHERE" });

Then to access the selected item: 然后访问所选项目:

 string Title = (CmbVendor.SelectedItem as VendorNames).Name.ToString()

This is just pseudo code hopefully to get you going along the lines. 这只是伪代码,希望能使您步入正轨。

I have the Modelclass like below. 我有下面的Modelclass。

public class Row
{
  public string vendor_id { get; set; }
  public string vendor_name { get; set; }
}

Then in your function 然后在你的职能

var value = CmbVendor.SelectedItem as Row;

and then 接着

Dictionary<string, string> pairs = new Dictionary<string, string>();
pairs.Add("vendorID", value.vendor_id);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从Windows Phone 8.1中的AutoSuggestBox获取所选项目 - How to get selected item from AutoSuggestBox in Windows Phone 8.1 Windows 8.1或Windows Phone 8.1中的ComboBox所选项目 - ComboBox selected item in windows 8.1 or windows phone 8.1 Windows Phone 8.1通过按住选择列表视图中的项目 - Windows Phone 8.1 select an item in a listview by holding 获取ListPicker Windows Phone 8.1 Silverlight中所选项目的价值 - Get Value for selected Item in ListPicker Windows Phone 8.1 Silverlight 如何从Windows Phone 8.1中的ListView(SQLite数据库)中删除所选项目 - How to delete the selected item from listview(sqlite database) in windows phone 8.1 如何从选定的项目ListPicker Windows Phone 8.1 Silverlight获取内容文本? - How to get the content text from the selected item ListPicker Windows Phone 8.1 Silverlight? 在Windwos Phone 8.1 Silverlight中,如何从列表框中删除选定的项目 - How to remove selected item from ListBox in windwos phone 8.1 Silverlight 如何在Windows Phone 8.1中将图标和背景色设置为Combox项 - How to set icon and background color to Combox item in Windows Phone 8.1 如何滚动到Windows Phone 7中列表框中的选定项目 - How to Scroll into selected item in listbox in windows phone 7 如何选择Windows Phone 7.1中列表框中的项目 - how to select an item in listbox in windows phone 7.1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM