How to display JSON in WPF TreeView

后端 未结 3 1197
感情败类
感情败类 2020-12-18 15:54

I am reading in JSON and then displaying it in a WPF treeview.

Here is the code...

Class MainWindow
Public Sub New()

    InitializeComponent()
    D         


        
3条回答
  •  隐瞒了意图╮
    2020-12-18 16:51

    The problem is that your XAML can only show a collections in dictionary's value and if there is a string, then it will be considered as collection of characters. One of the quick sollutions is to create a converter, which will transform your strings into string collections.

    For this you need a value converter(sorry I do code in c#)

    public class ValConv : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is string str)
            {
                return new List { str };
            }
            return value;
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value;
        }
    }
    


    Instantiate this converter in resources:

    
    
    
    


    and use it:

    
    

提交回复
热议问题