다음을 통해 공유


방법: Freezable의 고정 여부 확인

업데이트: 2007년 11월

이 예제에서는 Freezable 개체의 고정 여부를 확인하는 방법을 보여 줍니다. 고정된 Freezable 개체를 수정하려고 하면 InvalidOperationException이 throws됩니다. 이 예외가 throw되지 않도록 하려면 Freezable 개체의 IsFrozen 속성을 사용하여 고정 여부를 확인합니다.

예제

다음 예제에서는 SolidColorBrush를 고정한 다음 IsFrozen 속성으로 테스트하여 고정 여부를 확인합니다.

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;
}


Freezable 개체에 대한 자세한 내용은 Freezable 개체 개요를 참조하십시오.

참고 항목

개념

Freezable 개체 개요

참조

Freezable

IsFrozen

기타 리소스

기본 요소 방법 항목