一个类(稍后用作datacontext):
[Serializable]
public class CMiXData : INotifyPropertyChanged
{
public CMiXData() { }
private ObservableCollection<string> _ChannelsSpriteCount = new ObservableCollection<string>(new[] { "1", "1", "1", "1", "1", "1" });
public ObservableCollection<string> ChannelsSpriteCount
{
get { return _ChannelsSpriteCount; }
set { _ChannelsSpriteCount = value; }
}
某些usercontrol
绑定到此类的属性ChannelsSpriteCount
,并且序列化后保存的json
可能如下所示:
{"ChannelsSpriteCount":["32","4","8","64","2","4"]}
当我以这种方式加载和反序列化json文件时:
private void Load_Click(object sender, RoutedEventArgs e)
{
this.DataContext = JsonConvert.DeserializeObject<CMiXData>(File.ReadAllText(@"C:\Users\BabyClone\Documents\cmix.json"));
MessageBox.Show(cmixdata.ChannelsSpriteCount[0]);
无论我在保存的文件中看到什么值,加载的内容始终是原始类的默认值:在这种情况下"1"
...
我在这里缺少什么?