WPF 数据绑定 定制一个集合的视图

无论何时绑定一个集合,都会有一个默认的视图隐式被插入到源对象和目标对象之间,该视图(实现ICollectionView接口的对象),存储当前信息。

 

排序

//排序
private void SortHelper(string propertyName)
{
    //返回给定源的默认视图
    //ICollectionView view = CollectionViewSource.GetDefaultView(this.FindResource("photoList");
    ICollectionView view = CollectionViewSource.GetDefaultView(pl);

    //ICollectionView的SortDescriptions属性来控制视图排序
    if (view.SortDescriptions.Count > 0
        && view.SortDescriptions[0].PropertyName == propertyName
        && view.SortDescriptions[0].Direction == ListSortDirection.Ascending)
    {
        view.SortDescriptions.Clear();
        view.SortDescriptions.Add(new SortDescription(propertyName, ListSortDirection.Descending));
    }
    else
    {
        view.SortDescriptions.Clear();
        view.SortDescriptions.Add(new SortDescription(propertyName, Li
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
WPF LiveCharts 是一个用于 WPF 应用程序的开源图表控件库,它提供了多种类型的图表和动画效果。要在 WPF LiveCharts 中进行数据,可以按照以下步骤进行操作: 1. 引用 LiveCharts.Wpf 和 LiveCharts.Geared 库。 2. 在 XAML 中添加一个 Chart 控件,例如: ``` <lvc:CartesianChart Series="{Binding DataSeries}" LegendLocation="Bottom"/> ``` 这里的 DataSeries 是你在 ViewModel 中义的数据集合,它需要实现 INotifyPropertyChanged 接口以便在数据发生更改时通知视图更新。 3. 在 ViewModel 中义 DataSeries 属性,并在构造函数中初始化: ``` private SeriesCollection _dataSeries; public SeriesCollection DataSeries { get { return _dataSeries; } set { _dataSeries = value; OnPropertyChanged(nameof(DataSeries)); } } public ViewModel() { // 初始化数据集合 DataSeries = new SeriesCollection { new LineSeries { Title = "Series 1", Values = new ChartValues<double> { 1, 3, 2, 4 } }, new LineSeries { Title = "Series 2", Values = new ChartValues<double> { 4, 2, 1, 3 } } }; } ``` 这里使用了 LineSeries 类型的图表,并将其添加到 DataSeries 集合中。 4. 在 ViewModel 中实现 INotifyPropertyChanged 接口: ``` public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged(string propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } ``` 这样就可以在 ViewModel 中更改 DataSeries 集合,并通过数据自动更新视图中的图表了。 希望这些步骤能够帮助你进行 WPF LiveCharts 的数据

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值