相关文章推荐
无邪的大熊猫  ·  VUE3+Typescript ...·  6 月前    · 
温柔的炒粉  ·  javascript - ...·  1 年前    · 
英勇无比的野马  ·  javascript - ...·  1 年前    · 

System.Windows.Freezable类(在 WindowsBase.dll 中)定义一个对象,该对象具有可修改状态和只读(冻结)状态。派生自 Freezable 的类提供详细的更改通知,可以是不可变的,并且可以进行自我克隆。
C#: public abstract class Freezable : DependencyObject
Freezable 类提供特殊功能,以便在使用修改或复制开销很大的对象时帮助 提高应用程序性能
比如,常见的Freezable对象Brush,Pen,Geometry,Transform,AnimationTimeline(事实上,它们都继承自 System.Windows.Media.Animation. Animatable,而 Animatable又继承自 System.Windows.Freezable,见后面的 继承层次结构 )等。

派生自 Freezable 的类可以获得以下功能:
(1)特殊状态: 只读(冻结)状态 可写状态
(2)线程安全性:可以 在线程之间共享冻结的 Freezable 对象
(3)详细的更改通知:与其他 DependencyObject 对象不同,Freezable 对象可 在子属性值更改时提供更改通知
(4)便于克隆:Freezable 类已经实现了多种生成 深层克隆 的方法。

需要注意的是,如果以下任何一个对象相关条件为 true,则无法冻结 Freezable 对象:
(1)它 有动画或数据绑定的属性
(2)它 有由动态资源设置的属性
(3)它 包含无法冻结的 Freezable 子对象
如果这些条件对于 Freezable 对象为 false,并且您不希望修改它,请将其冻结以提高性能。将对象冻结,可以提高效率,因为被冻结的对象不会被改变,因此它们不需要监控。

SolidColorBrush属于Freezable 对象类型,下例演示如何通过调用其 Freeze 方法使 Freezable 变为只读。
C#代码:
Button button = new Button();
SolidColorBrush solidColorBrush = new SolidColorBrush(Colors.Red);
if (solidColorBrush.CanFreeze)
{
// 使画刷不可更改(冻结)
solidColorBrush.Freeze();
}
button.Background = solidColorBrush;

上例需要注意一点,如果SolidColorBrush solidColorBrush = new SolidColorBrush(Colors.Red);   这一行改成:
SolidColorBrush solidColorBrush = Brushes.Red;  则solidColorBrush处于冻结状态。也就是说,不能再被改变。同理,从SystemColors返回的画刷对象也是冻结的。比如:
Brush brush = SystemColors.WindowBrush; 这时的brush不允许改变它。
但可以使用:Brush brush = new SystemColorBrush(SystemColors.WindowColor);  //这个brush可以改变

如上面代码所示,如果Freezable对象的CanFreeze属性是true,则可调用Freeze()方法来实现对象的冻结和不可变动。确定 Freezable 是否处于冻结状态:使用 Freezable 对象的 IsFrozen 属性来确定对象是否处于冻结状态。也就是说,如果某Freezable对象的IsFrozen属性如果变成true,则表示此对象已经被冻结。

没有办法将已冻结的对象解冻(unfreeze),但你可以使用 Clone() 方法来创建只读 Freezable对象 的可写副本,这个副本就是没有冻结的。
冻结的Freezable对象可以在不同的线程之间共享,但没有被冻结的Freezable对象则不行。
只有继承自Freezable类的对象,才可以被冻结。

继承层次结构
System.Object
System.Windows.Threading.DispatcherObject
System.Windows.DependencyObject
System.Windows.Freezable
System.Windows.Media.Animation. Animatable
System.Windows.FreezableCollection<(Of <(T>)>)
System.Windows.Media.Animation. Timeline
System.Windows.Media.Animation.TimelineCollection
System.Windows.Media. Brush
System.Windows.Media.DashStyle
System.Windows.Media.Drawing
System.Windows.Media.DrawingCollection
System.Windows.Media.Effects. BitmapEffect
System.Windows.Media.Effects.BitmapEffectCollection
System.Windows.Media.Effects.BitmapEffectInput
System.Windows.Media.GeneralTransform
System.Windows.Media.GeneralTransformCollection
System.Windows.Media. Geometry
System.Windows.Media.GeometryCollection
System.Windows.Media. GradientStop
System.Windows.Media.GradientStopCollection
System.Windows.Media.GuidelineSet
System.Windows.Media. ImageSource
System.Windows.Media.Media3D. Camera
System.Windows.Media.Media3D.Geometry3D
System.Windows.Media.Media3D.Material
System.Windows.Media.Media3D.MaterialCollection
System.Windows.Media.Media3D.Model3D
System.Windows.Media.Media3D.Model3DCollection
System.Windows.Media.Media3D.Rotation3D
System.Windows.Media.Media3D.Transform3D
System.Windows.Media.Media3D.Transform3DCollection
System.Windows.Media.MediaPlayer
System.Windows.Media.PathFigure
System.Windows.Media.PathFigureCollection
System.Windows.Media.PathSegment
System.Windows.Media.PathSegmentCollection
System.Windows.Media. Pen
System.Windows.Media.TextEffect
System.Windows.Media.TextEffectCollection
System.Windows.Media.TransformCollection
System.Windows. TextDecoration
System.Windows.TextDecorationCollection
System.Windows.Media.Animation.BooleanKeyFrame
System.Windows.Media.Animation.BooleanKeyFrameCollection
System.Windows.Media.Animation.ByteKeyFrame
System.Windows.Media.Animation.ByteKeyFrameCollection
System.Windows.Media.Animation.CharKeyFrame
System.Windows.Media.Animation.CharKeyFrameCollection
System.Windows.Media.Animation.ColorKeyFrame
System.Windows.Media.Animation.ColorKeyFrameCollection
System.Windows.Media.Animation.DecimalKeyFrame
System.Windows.Media.Animation.DecimalKeyFrameCollection
System.Windows.Media.Animation.DoubleKeyFrame
System.Windows.Media.Animation.DoubleKeyFrameCollection
System.Windows.Media.Animation.Int16KeyFrame
System.Windows.Media.Animation.Int16KeyFrameCollection
System.Windows.Media.Animation.Int32KeyFrame
System.Windows.Media.Animation.Int32KeyFrameCollection
System.Windows.Media.Animation.Int64KeyFrame
System.Windows.Media.Animation.Int64KeyFrameCollection
System.Windows.Media.Animation.KeySpline
System.Windows.Media.Animation.MatrixKeyFrame
System.Windows.Media.Animation.MatrixKeyFrameCollection
System.Windows.Media.Animation.ObjectKeyFrame
System.Windows.Media.Animation.ObjectKeyFrameCollection
System.Windows.Media.Animation.Point3DKeyFrame
System.Windows.Media.Animation.Point3DKeyFrameCollection
System.Windows.Media.Animation.PointKeyFrame
System.Windows.Media.Animation.PointKeyFrameCollection
System.Windows.Media.Animation.QuaternionKeyFrame
System.Windows.Media.Animation.QuaternionKeyFrameCollection
System.Windows.Media.Animation.RectKeyFrame
System.Windows.Media.Animation.RectKeyFrameCollection
System.Windows.Media.Animation.Rotation3DKeyFrame
System.Windows.Media.Animation.Rotation3DKeyFrameCollection
System.Windows.Media.Animation.SingleKeyFrame
System.Windows.Media.Animation.SingleKeyFrameCollection
System.Windows.Media.Animation.SizeKeyFrame
System.Windows.Media.Animation.SizeKeyFrameCollection
System.Windows.Media.Animation.StringKeyFrame
System.Windows.Media.Animation.StringKeyFrameCollection
System.Windows.Media.Animation.ThicknessKeyFrame
System.Windows.Media.Animation.ThicknessKeyFrameCollection
System.Windows.Media.Animation.Vector3DKeyFrame
System.Windows.Media.Animation.Vector3DKeyFrameCollection
System.Windows.Media.Animation.VectorKeyFrame
System.Windows.Media.Animation.VectorKeyFrameCollection
System.Windows.Media.DoubleCollection
System.Windows.Media.ImageMetadata
System.Windows.Media.Int32Collection
System.Windows.Media.Media3D.Point3DCollection
System.Windows.Media.Media3D.Vector3DCollection
System.Windows.Media.PointCollection
System.Windows.Media.VectorCollection

当 IsFrozen 属性为 false 时,只能从创建 Freezable 对象的线程访问此对象。如果尝试从其他线程访问,则会引发 InvalidOperationException。Dispatcher.Invoke 和 Dispatcher.BeginInvoke 方法提供封送处理到正确线程的支持。
当它们的 IsFrozen 属性为 true 时,Freezable 对象为自由线程对象。

注意结构体(structure)不存在冻结不冻结的问题。比如:Color。说白了,它并不是 继承自Freezable类的对象,而只有继承自Freezable类的对象,才可以被冻结。

本文实例讲述了C# WPF 使用多 线 程调用窗体组件的方法。分享给大家供大家参考。具体如下: Thread thread=new Thread(new ThreadStart(TestThread)); thread.Start(); private void TestThread() for (int i = 0; i < 11 xss=removed> { this.listBox1.Items.Add(this is a test!!!); } WPF 窗口及窗口上的控件是属于UI 线 程,可以再后台代码区直接使用控件属性,却不可以不可以再新建一个 线 操作控件,因为控件属于UI 线 程,你新建一个 线 程去调用UI 线 的控件属于跨 线 程访问, WPF 默认不能跨 线 程访问。下面讲解决方法,用到Dispatcher语句 //假设我想通过 线 程点击一下按钮改变TextBox属性 private void btnSend_Clic... WPF 虽然很美观,效果很炫,但是对资源的消耗也很大,尤其是初次接触 WPF 的人,因为很多地方虽然实现了想要的效果,但是由于经验 问题 ,所以也会造成很大的资源浪费,好的程序,需要更好的优化。虽然可能只是节省了很少的一点资源,但是对整体程序运行的速度与稳定性来说,也许就起到了决定性的作用;每个地方都能做到一点优化,那么在成个程序 ,优化的效果就会很明显,流畅、稳定,才是一个程序的健康状态。 以此为示例 def say_hi print "hello world" end namespace ConsoleApplication2 { public class Person : F   原文地址:http://www. wpf tutorial.net/10PerformanceTips.html Windows Presentation Foundation provides a very confortable way to developrich user experiences. A drop shadow for exam Freezable 類別 Defines an object that has a modifiable and a read-only ( frozen ) state. Classes that derive fr.. 在这个演示 ,我展示了如何使用 HostVisual 和 VisualTarget 类来组合来自不同 线 程的 UI 片段。有一些限制:即工作 线 程拥有的 UI 不接收输入事件。在此过程 ,我们还必须解决一些烦恼,但事实证明这些烦恼相当小。... 1 使用附加属性来添加动画 public static readonly DependencyProperty AniInvokePropery = DependencyProperty.RegisterAttached("AniInvoke", t...