方法 : Freezable を読み取り専用にする
この例では、Freeze メソッドを呼び出して、Freezable を読み取り専用にする方法を示します。
次に示す条件が 1 つでも true である場合は、Freezable オブジェクトを固定できません。
アニメーション化されたプロパティ、またはデータ バインドされたプロパティがある。
動的リソースによって設定されたプロパティがある。 動的リソースの詳細については、「リソースの概要」を参照してください。
固定できない Freezable のサブオブジェクトが含まれている。
Freezable オブジェクトに関してこれらの条件が false であり、オブジェクトを変更しない場合は、オブジェクトを固定して、性能の向上を図ることをお勧めします。
使用例
次の例では、Freezable オブジェクトの一種の SolidColorBrush を固定します。
Dim myButton As New Button()
Dim myBrush As New SolidColorBrush(Colors.Yellow)
If myBrush.CanFreeze Then
' Makes the brush unmodifiable.
myBrush.Freeze()
End If
myButton.Background = myBrush
Button myButton = new Button();
SolidColorBrush myBrush = new SolidColorBrush(Colors.Yellow);
if (myBrush.CanFreeze)
{
// Makes the brush unmodifiable.
myBrush.Freeze();
}
myButton.Background = myBrush;
Freezable オブジェクトの詳細については、「Freezable オブジェクトの概要」を参照してください。