本文整理汇总了C#中System.Windows.Freezable类的典型用法代码示例。如果您正苦于以下问题:C# Freezable类的具体用法?C# Freezable怎么用?C# Freezable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Freezable类属于System.Windows命名空间,在下文中一共展示了Freezable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CloneCurrentValueCore
/// <summary>
/// Copies data into a cloned instance.
/// </summary>
/// <param name="source">
/// The original instance to copy data from.
/// </param>
/// <remarks>
/// When a Freezable's "current value" is cloned, WPF will make
/// deep clones of the "current values" of all writable,
/// locally-set properties. This has the effect of resolving
/// expressions to their values. WPF skips read only DPs.
///
/// If you derive from this class and have additional non-DP state
/// that should be transfered to copies, you should override the
/// CopyCommon method.
/// </remarks>
protected sealed override void CloneCurrentValueCore(Freezable source)
{
base.CloneCurrentValueCore(source);
CustomBitmap customBitmapSource = (CustomBitmap)source;
CopyCore(customBitmapSource, /*useCurrentValue*/ true, /*willBeFrozen*/ false);
}
示例2: FreezableBasicTest
public void FreezableBasicTest()
{
int resourcesChangedCount = 0;
object resourceValue;
Freezable freezable = new Freezable();
freezable.ResourcesChanged += (sender, e) => resourcesChangedCount++;
FrameworkElement element = new FrameworkElement();
element.DataContext = "data-context";
element.Resources = new ResourceDictionary();
element.Resources.Add("key1", "value1");
Assert.AreNotEqual("data-context", freezable.GetValue(FrameworkElement.DataContextProperty));
Assert.IsFalse(freezable.TryGetResource("key1", out resourceValue));
element.SetValue(ValueProperty, freezable);
Assert.AreEqual("data-context", freezable.GetValue(FrameworkElement.DataContextProperty));
Assert.AreEqual(1, resourcesChangedCount);
Assert.IsTrue(freezable.TryGetResource("key1", out resourceValue));
Assert.AreEqual("value1", resourceValue);
element.Resources.Add("key2", "value2");
Assert.AreEqual(2, resourcesChangedCount);
Assert.IsTrue(freezable.TryGetResource("key2", out resourceValue));
Assert.AreEqual("value2", resourceValue);
}
示例3: FreezableDefaultValueFactory
/// <summary>
/// Stores a frozen copy of defaultValue
/// </summary>
internal FreezableDefaultValueFactory(Freezable defaultValue)
{
Debug.Assert(defaultValue != null,
"Null can not be made mutable. Do not use FreezableDefaultValueFactory.");
Debug.Assert(defaultValue.CanFreeze,
"The defaultValue prototype must be freezable.");
_defaultValuePrototype = defaultValue.GetAsFrozen();
}
示例4: GetAsFrozen
/// <summary>
/// Semantically equivilent to Freezable.Clone().Freeze() except that
/// GetAsFrozen avoids copying any portions of the Freezable graph
/// which are already frozen.
/// </summary>
public static Freezable GetAsFrozen(Freezable freezable)
{
if (freezable == null)
{
return null;
}
return freezable.GetAsFrozen();
}
示例5: Clone
//------------------------------------------------------
//
// Constructors
//
//------------------------------------------------------
//------------------------------------------------------
//
// Internal Methods
//
//------------------------------------------------------
#region Internal Methods
/// <summary>
/// A null-safe wrapper around Freezable.Clone(). (If a null
/// is encountered it returns null.)
/// </summary>
internal static Freezable Clone(Freezable freezable)
{
if (freezable == null)
{
return null;
}
return freezable.Clone();
}
示例6: CloneCore
/// <summary/>
protected override void CloneCore(Freezable sourceFreezable) {
base.CloneCore(sourceFreezable);
//TODO: Investigate why the following loop is needed. From the API docs, the Children collection should have cloned itself.
var sourceCollection = ((CompositeEffect)sourceFreezable).Children;
foreach (var child in sourceCollection) {
Children.Add((Effect)child.Clone());
}
}
示例7: FreezableProxyCommand
public FreezableProxyCommand(Freezable freezable, string name)
: base(null, name)
{
_freezable = freezable;
var evt = _freezable.GetType().GetEvent("InheritanceContextChanged",
BindingFlags.Instance | BindingFlags.NonPublic);
var addMethod = evt.GetAddMethod(true);
addMethod.Invoke(freezable, new[] {new EventHandler(OnInheritanceContextChanged)});
SetFrameworkElementFromInheritanceContext();
}
示例8: GetAsFrozenIfPossible
/// <summary>
/// If freezable is already frozen, it returns freezable
/// If freezable is not frozen, it returns a copy that is frozen if possible
/// </summary>
internal static Freezable GetAsFrozenIfPossible(Freezable freezable)
{
if (freezable == null)
{
return null;
}
if (freezable.CanFreeze)
{
freezable = freezable.GetAsFrozen();
}
return freezable;
}
示例9: FreezableCollectionBasicTest
public void FreezableCollectionBasicTest()
{
int resources1ChangedCount = 0;
object resourceValue;
Freezable freezable1 = new Freezable();
freezable1.ResourcesChanged += (sender, e) => resources1ChangedCount++;
FreezableCollection<Freezable> freezableCollection = new FreezableCollection<Freezable> { freezable1 };
FrameworkElement element = new FrameworkElement();
element.DataContext = "data-context";
element.Resources = new ResourceDictionary();
element.Resources.Add("key1", "value1");
Assert.IsNull(freezable1.GetValue(FrameworkElement.DataContextProperty));
Assert.IsFalse(freezable1.TryGetResource("key1", out resourceValue));
element.SetValue(ValueProperty, freezableCollection);
Assert.AreEqual("data-context", freezable1.GetValue(FrameworkElement.DataContextProperty));
Assert.AreEqual(2, resources1ChangedCount);
Assert.IsTrue(freezable1.TryGetResource("key1", out resourceValue));
Assert.AreEqual("value1", resourceValue);
Freezable freezable2 = new Freezable();
freezableCollection.Add(freezable2);
Assert.AreEqual("data-context", freezable2.GetValue(FrameworkElement.DataContextProperty));
Assert.IsTrue(freezable2.TryGetResource("key1", out resourceValue));
Assert.AreEqual("value1", resourceValue);
freezableCollection.Clear();
Assert.AreNotEqual("data-context", freezable1.GetValue(FrameworkElement.DataContextProperty));
Assert.AreNotEqual("data-context", freezable2.GetValue(FrameworkElement.DataContextProperty));
Assert.AreEqual(3, resources1ChangedCount);
Assert.IsFalse(freezable1.TryGetResource("key1", out resourceValue));
Assert.IsFalse(freezable2.TryGetResource("key1", out resourceValue));
}
示例10: GetCurrentValueAsFrozenCore
protected override void GetCurrentValueAsFrozenCore (Freezable sourceFreezable)
{
throw new NotImplementedException ();
}
示例11: GetCurrentValueAsFrozenCore
protected override void GetCurrentValueAsFrozenCore(Freezable sourceFreezable)
{
base.GetCurrentValueAsFrozenCore(sourceFreezable);
CloneCommon(sourceFreezable);
}
示例12: GetCurrentValueAsFrozenCore
/// <summary>
/// Implementation of <see cref="System.Windows.Freezable.GetCurrentValueAsFrozenCore(Freezable)">Freezable.GetCurrentValueAsFrozenCore</see>.
/// </summary>
protected override void GetCurrentValueAsFrozenCore(Freezable source)
{
CharAnimationUsingKeyFrames sourceAnimation = (CharAnimationUsingKeyFrames) source;
base.GetCurrentValueAsFrozenCore(source);
CopyCommon(sourceAnimation, /* isCurrentValueClone = */ true);
}
示例13: GetAsFrozenCore
/// <summary>
/// Implementation of <see cref="System.Windows.Freezable.GetAsFrozenCore(Freezable)">Freezable.GetAsFrozenCore</see>.
/// </summary>
protected override void GetAsFrozenCore(Freezable source)
{
DecimalAnimationUsingKeyFrames sourceAnimation = (DecimalAnimationUsingKeyFrames) source;
base.GetAsFrozenCore(source);
CopyCommon(sourceAnimation, /* isCurrentValueClone = */ false);
}
示例14: AddChangedHandler
public void AddChangedHandler(Freezable resource)
{
// If _resource already exists, unhook the event handler.
if (_resource != null)
{
RemoveChangedHandler();
}
_resource = resource;
Debug.Assert(!_resource.IsFrozen);
_resource.Changed += new EventHandler(this.InvalidateTargetSubProperty);
}
示例15: CloneCore
/// <summary>
/// Implementation of Freezable.CloneCore()
/// </summary>
protected override void CloneCore(Freezable source)
{
base.CloneCore(source);
StreamGeometry sourceStream = (StreamGeometry) source;
if ((sourceStream._data != null) && (sourceStream._data.Length > 0))
{
_data = new byte[sourceStream._data.Length];
sourceStream._data.CopyTo(_data, 0);
}
}