优先级绑定 PriorityBinding msdn 虚拟化数据 public class VirtualizedCollection T : ObservableCollection T , ...
优先级绑定
PriorityBinding msdn
虚拟化数据
public class VirtualizedCollection<T> : ObservableCollection<T>,
IList,
ICollectionViewFactory
{
private readonly Func<int, int, IEnumerable<T>> _dataFetcher;
public VirtualizedCollection(Func<int, int, IEnumerable<T>> dataFetcher,
int totalCount)
{
_dataFetcher = dataFetcher;
TotalCount = totalCount;
}
protected override void InsertItem(int index, T item)
{
if(index >= Count && index < TotalCount)
{
var items = _dataFetcher(index, 50); // 每次加载50条
foreach(var it in items)
{
base.InsertItem(index++, it);
}
}
}
}
冻结对象
var brush = new LinearGradientBrush();
brush.Freeze(); // 禁止后续修改,提升渲染性能
actipro 控件 textbox propertyChanged属性通知失败,试一试commitTrigger属性
在 WPF 中,Dispatcher 是 UI 线程的消息调度系统,所有 UI 控件的操作都必须在 UI 线程 执行。
System.Windows.Threading.DispatcherPriority 就是用来指定任务在消息队列中的优先级,即你提交给 Dispatcher 的操作什么时候执行。
1️⃣ 常用优先级枚举
枚举 描述
Inactive 永不执行,除非显式调用
SystemIdle 系统空闲时才执行,优先级最低
ApplicationIdle 应用空闲时执行(高于 SystemIdle)
ContextIdle 当前上下文空闲时执行
Background 后台任务,优先级低于输入/渲染/正常事件
Input 响应输入事件之前执行,优先级高
Loaded 控件加载完成后执行
Render UI 渲染之前执行,保证界面更新前完成
DataBind 数据绑定更新的优先级
Normal 默认优先级,一般情况下使用这个
Send 立即执行,相当于同步调用
使用举例
this.Context.Dispatcher.BeginInvoke(new Action(() =>
{
myLabel.Content = "更新UI";
}), DispatcherPriority.Normal);