[英]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.