【发布时间】:2020-01-10 06:05:46
【问题描述】:
我正在开发一个 uwp 应用程序,我从 json 加载数据并将其保存在那里 我想要的是将父对象内的子对象移动到另一个父对象 通过界面列表视图的拖放功能
我正在使用 ObservableCollection 使用 foreach 迭代它们并将数据加载到列表中 使用 listview.ItemsSoure。
我有很多疑问,例如: * 如何知道我拖的是什么项目? * 如何在目标列表视图中检测我正在释放项目、对象、observableCollection? * 如何将子对象移动到父对象 但我不知道从哪里开始 我什至不知道我的计划是正确还是行不通
我的文件 json 数据:
{
"date": 737282,
"notebooks": [
{
"title": "Bienvenido",
"created": 0,
"notes": [
{
"title": "una nota que ya funciona ",
"id": "SoYnXQslbxDTe",
"created": 737307,
"updated": 737309,
"text": "de forma excepcional"
},
{
"title": "agregar nuevas notas mas eficaces cada vez mas rapidos this is great",
"id": "HGHQVRgpuvqrqs",
"created": 737307,
"updated": 737309,
"text": ""
},
{
"title": "intrensent and lorem ipsum dolor camen argon ersom",
"id": "plwjWxOGaHhpg",
"created": 737307,
"updated": 737309,
"text": "indelimit arkenson auk kalemer amred yut hyt"
}
],
"id": "section1",
"updated": 0
},
{
"title": "bnfgdgh",
"created": 737307,
"notes": [
{
"title": "Bienvenido a la nueva version",
"id": "eoERbgGDrdxDz",
"created": 737307,
"updated": 737309,
"text": "welcome to new note sample"
},
{
"title": "un item que no puedes reordenar",
"id": "VSyL_HaV-tdEWz",
"created": 737307,
"updated": 737309,
"text": "gdhgdh"
}
],
"id": "jwhsEbLMF",
"updated": 737307
},
{
"title": "Faus inside order",
"created": 737307,
"notes": [
{
"title": "mi nueva nota",
"id": "qX-jM_s",
"created": 737307,
"updated": 737309,
"text": ""
},
{
"title": "dfdfd",
"id": "CDTDjNLQ_",
"created": 737307,
"updated": 737309,
"text": "dfgdfgdf"
},
{
"title": "dfdfd",
"id": "zhhskohLLEYh",
"created": 737307,
"updated": 737309,
"text": ""
}
],
"id": "muNVWlFNbyYdgP",
"updated": 737307
}
],
"version": 1
}
我的模型类:
public class Notes : INotifyPropertyChanged
{
private string Title;
public string title
{
get {return Title; }
set
{
Title = value;
NotifyPropertyChanged("title");
}
}
public string id { get; set; }
public int created { get; set; }
public int updated { get; set; }
public string text { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this,new PropertyChangedEventArgs(propertyName));
}
}
}
public class Notebook
{
public string title { get; set; }
public int created { get; set; }
public List<Notes> notes { get; set; }
public string id { get; set; }
public int updated { get; set; }
}
public class Libro
{
public int date { get; set; }
public List<Notebook> notebooks { get; set; }
public int version { get; set; }
}
我要移动的列表视图:
<ListView
x:Name="ListaNotas"
CanDragItems="True"
CanReorderItems="True"
AllowDrop="True"
IsItemClickEnabled="True"
ItemsSource="{Binding Mynotes}"
SelectedItem="{Binding SelectItem, Mode=TwoWay}"/>
我的列表视图放置目标:
<ListView
x:Name="listaSections"
Margin="0"
Padding="0"
AllowDrop="True"
CanReorderItems="True"
CanDragItems="True"
IsItemClickEnabled="True"
/>
【问题讨论】: