开发者

Assigning DependencyProperty runs slow

开发者 https://www.devze.com 2023-04-12 06:37 出处:网络
There is Button button1 and TextBox textBox1. Here\'s button1\'s ClickEvent hadler: priv开发者_如何学Pythonate void button1_Click(object sender, RoutedEventArgs e)

There is Button button1 and TextBox textBox1. Here's button1's ClickEvent hadler:

priv开发者_如何学Pythonate void button1_Click(object sender, RoutedEventArgs e)
{
    DateTime now = DateTime.Now;
    textBox1.Text = "some text";
    TimeSpan span = DateTime.Now - now;
    MessageBox.Show(span.TotalMilliseconds.ToString());
}            

span.TotalMilliseconds is 1...2 in Debug and 0...1 in Release. But even in Release it has value of "0" only in about 2 times of 10.

Question is, why is it so slow?

I am implementing my own control similar to DataGrid and I have about 300 visible cells on screen. I implemented my own UI virtualization that is based on moving data "behind" the cells. So every time I scroll each cell's text gets updated. And it lasts more than 300 milliseconds.

0

精彩评论

暂无评论...
验证码 换一张
取 消