在test.xaml
中<rlb:ReorderListBox
x:Name="reorderListBox"
Grid.Row="2"
Margin="12,0,12,12"
IsReorderEnabled="True"
ItemsSource="{Binding}" >
<rlb:ReorderListBox.ItemTemplate>
<DataTemplate>
<TextBlock
Margin="12,4,12,4"
FontSize="36"
Text="{Binding Name}" />
</DataTemplate>
</rlb:ReorderListBox.ItemTemplate>
</rlb:ReorderListBox>
int Test.xaml.cs
public void loadSource()
{
try
{
var xElem = XElement.Load("Data/SourcePage.xml");
var SourceNews =
from elem in xElem.Descendants("SourceNews")
select new ProNewsApp.Object.ObjectSource
{
Name = elem.Attribute("PageName").Value
};
reorderListBox.DataContext = SourceNews.ToList();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
我跟在这里http://reorderlistbox.codeplex.com/我的问题是当我拖放并且我的应用程序已关闭时?为什么在我拖动项目时它已关闭?我该如何解决?它
答案 0 :(得分:1)
您需要使用ObservableCollection作为ReorderListBox的源。由于ReorderListbox在模型中重新排序项目时更改索引。所以,尝试使用:
System.Collections.ObjectModel.ObservableCollection<YourPublicClass> _observableList;
_observableList = new System.Collections.ObjectModel.ObservableCollection<YourPublicClass>(SourceNews.ToList());
reorderListBox.DataContext = _observableList;
重新排列项目后,您可以看到它们也被更改为&#34; _observableList&#34;。