c# - 如何将组合框选择的项目转换为字符串

标签 c# xaml

我如何让我的组合框选择的项目从项目源填充到字符串,这样我就可以在我的帖子中使用它,就像 string bolts = comboBox_Copy.Text; 或者string bolts = comboBox.Copy.SelectedItem; 给出 null

     private void boltPatterns()
    {
        {
            try
            {
                string Url = URL_Domain + "resources/bolt-pattern";
                Uri serviceUri = new Uri(Url);
                using (WebClient webClient = new WebClient())
                {
                    webClient.Encoding = Encoding.UTF8;
                    string api = webClient.DownloadString(serviceUri);

                    List<boltPatterns> values =  JsonConvert.DeserializeObject<List<boltPatterns>>(api);
                    comboBox_Copy.ItemsSource= values;
                }
            }

XAML

 <ComboBox x:Name="comboBox_Copy" DisplayMemberPath="BoltPattern" SelectedItem="{Binding BoltPattern}">

最佳答案

string bolts = comboBox.SelectedItem.ToString();

关于c# - 如何将组合框选择的项目转换为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46681280/

相关文章:

c# - 如何在Windows 8.1中获取WPF窗口的标题栏颜色?

C#在重定向的HttpWebRequest中发送cookie

c# - DataGridView 验证 - 删除错误指示器

c# - 形状类型绑定(bind)

c# - 将数据从属性绑定(bind)到文本 block - MVVM Light 和 WPF

c# - 必须设置 ServiceLocationProvider

c# - Fluent NHibernate 的长度属性不适用于更新

c# - 在使用 ItemsSource 之前,项目集合必须为空

c# - 列表框对齐 WPF 内的复选框

wpf - 如何增加组合框显示项目的填充?