嗨我創建了這個小例子,我想擴展它以支持排序。展開Wpf Treeview支持排序
public class Country
{
public string Name { get; set; }
public int SortOrder { get; set; }
}
我的XAML:
<TreeView Name="CountryTreeView" ItemsSource="{Binding}">
<TreeView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Name}"/>
</DataTemplate>
</TreeView.ItemTemplate>
</TreeView>
和代碼隱藏:
readonly ObservableCollection<Country> Countries;
public MainWindow()
{
InitializeComponent();
Countries = new ObservableCollection<Country>
{
new Country{Name = "Denmark", SortOrder = 0},
new Country{Name = "Norway", SortOrder = 1},
new Country{Name = "Sweden", SortOrder = 2},
new Country{Name = "Iceland", SortOrder = 3},
new Country{Name = "Greenland", SortOrder = 4},
};
CountryTreeView.DataContext = Countries;
}
,我想有可能爲Treeview
排序的Countries
取決於SortOrder
值。
它需要能夠在飛行中做到這一點。 因此,如果我例如更改SortOrder
= 10的名稱=「丹麥」TreeView
會自動反映這一點。