您的位置:首页 > 理论基础 > 计算机网络

如何处理frozon control (WPF FAQ http://www.syncfusion.com/faq/wpf/default.aspx#60)

2008-10-20 15:22 603 查看
将一个control freeze后能够提高其性能。

If you try to modify a frozen Freezable object, it throws an 'Invalid Operation' Exception. To avoid throwing this exception, use the "IsFrozen" property of the Freezable object to determine whether it is frozen.

Button myButton = new Button();

SolidColorBrush myBrush = new SolidColorBrush(Colors.Yellow);

if (myBrush.CanFreeze)

{

// Makes the brush unmodifiable.

myBrush.Freeze();

}

myButton.Background = myBrush;

if (myBrush.IsFrozen) // Evaluates to true.

{

// If the brush is frozen, create a clone and

// modify the clone.

SolidColorBrush myBrushClone = myBrush.Clone();

myBrushClone.Color = Colors.Red;

myButton.Background = myBrushClone;

}

else

{

// If the brush is not frozen,

// it can be modified directly.

myBrush.Color = Colors.Red;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐