In 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
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.
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.