组合框分割值最多为1个字符,只从json获取第一个值

时间:2017-10-10 09:37:42

标签: c# xaml

我正在尝试使用带有大约30个值的json字符串填充我的组合框

但它只取第一个值(4x98)并将其拆分,因此它是

  • 4
  • X
  • 9
  • 8

       private void bindkrydsmål()
      {
    {
        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.DataContext = values;
            }
        }
    
        catch (Exception es)
        {
    
        }
    }
    }
     public class boltPatterns
      {           
        public string BoltPattern { get; set; }
      }
    

combobox xaml

<ComboBox x:Name="comboBox_Copy" ItemsSource="{Binding Path=BoltPattern}" Width="150" Height="40" Foreground="#FF00FB0B" Background="#FF303030" FontSize="16"  Canvas.Left="1030" Canvas.Top="24" Style="{StaticResource ComboBoxTest2}">

api值

"[{\"BoltPattern\":\"4x98\"},{\"BoltPattern\":\"5x108\"},{\"BoltPattern\":\"5x114.3\"},{\"BoltPattern\":\"6x180\"},{\"BoltPattern\":\"4x100\"},{\"BoltPattern\":\"8x165.1\"},{\"BoltPattern\":\"5x100\"},{\"BoltPattern\":\"5x165\"},{\"BoltPattern\":\"5x120.65\"},{\"BoltPattern\":\"6x115\"},{\"BoltPattern\":\"6x127\"},{\"BoltPattern\":\"5x118\"},{\"BoltPattern\":\"5x150\"},{\"BoltPattern\":\"5x127\"},{\"BoltPattern\":null}]"

1 个答案:

答案 0 :(得分:0)

它只需要一个属性名称来绑定。休息一切都很好

DisplayMemberPath="BoltPattern"

comboBox_Copy.ItemsSource= values;