[WPF] Freezable

C#/WPF 2023. 4. 14. 22:50
728x90
728x170

객체에 대한 변경이 일어나는 경우 Change 이벤트가 발생되는데 Freezable 은 고정항목으로 정의를 해줌으로써 더 이상 변경이 일어날 수 없도록 하여 애플리케이션 성능을 개선하는 데 도움이 될 수 있는 특수 기능을 제공합니다.

아래처럼 Brush 의 Freeze() 메서드를 호출하게 되면 더 이상 변경을 허용하지 않게 되므로 Brush.Color 변경 시 에러가 발생되게 됩니다.

Button myButton = new Button();
SolidColorBrush myBrush = new SolidColorBrush(Colors.Yellow);

if (myBrush.CanFreeze)
{
    // Makes the brush unmodifiable.
    myBrush.Freeze();
}

myButton.Background = myBrush;

try 
{
    // Throws an InvalidOperationException, because the brush is frozen.
    myBrush.Color = Colors.Red;
}
catch(InvalidOperationException ex)
{
    MessageBox.Show("Invalid operation: " + ex.ToString());
}

freezable 은 그래픽 객체를 그리는 경우 속도를 향상시키기 위해 쓰입니다.

특정 객체가 Freeze 된다면 그래픽 시스템은 해당 객체에 대해 더 이상 신경을 안 써도 되기 때문에 성능향상이 되는 것입니다.

 

728x90
그리드형

'C# > WPF' 카테고리의 다른 글

[WPF] Size3DConverter  (0) 2023.04.18
[WPF] PointConverter  (0) 2023.04.18
[C#/WPF] ColorSlider  (0) 2023.03.30
[C#/WPF] WPF 로 만든 Scratch 프로그램  (0) 2023.03.28
[WPF]두 컨트롤의 속성 바인딩  (0) 2023.03.17
Posted by kjun
,