WPF INotifyPropertyChanged

INotifyPropertyChanged ์ธํ„ฐํŽ˜์ด์Šค์˜ PropertyChanged ์ด๋ฒคํŠธ ์“ฐ์‹œ๋Š” ๋ถ„ ์žˆ์œผ์‹ ๊ฐ€์š”?
์ €๋Š” ๊ฐœ๋ฐœํ•  ๋•Œ ์ž์ฃผ ์“ฐ๋Š” ํŽธ์ด๋ผ ์˜ฌ๋ ค๋ด…๋‹ˆ๋‹ค.
PropertyChangedBase๋Š” MVVM Framework์ค‘ Caliburn.Micro๋ฅผ ์‚ฌ์šฉํ•˜์˜€์Šต๋‹ˆ๋‹ค.

public class MainWindowViewModel : PropertyChangedBase
    {
        private string _strTest;
        public string StrTest
        {
            get => _strTest;
            set => Set(ref _strTest, value);
        }

        private int _intTest;
        public int IntTest
        {
            get => _intTest;
            set => Set(ref _intTest, value);
        }

        public MainWindowViewModel()
        {
            this.PropertyChanged += MainWindowViewModel_PropertyChanged;
        }

        private void MainWindowViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            switch (e.PropertyName)
            {
                case nameof(StrTest):
                    if (!string.IsNullOrEmpty(StrTest))
                    {
                        //TODO:
                    }
                    break;
                case nameof(IntTest):
                    if (IntTest > 0)
                    {
                        //TODO:
                    }
                    break;

                default:
                    break;
            }
        }
    }
์ข‹์•„์š” 4

INotifyPropertyChanged ์—†์œผ๋ฉด ๊ฐœ๋ฐœ ๋ชปํ•˜๋Š” ์ˆ˜์ค€์ด์ฃ  ใ…Žใ…Ž MVVM ํŒจํ„ด์—์„œ ๋น ์งˆ ์ˆ˜ ์—†์œผ๋‹ˆ๊นŒ์š”.

์ข‹์•„์š” 3

์ €์˜ ๊ฒฝ์šฐ์—๋Š” ์ •๋ง ๋ง ๊ทธ๋Œ€๋กœ Property Changed ํ–ˆ๋‹ค๋Š” ์•Œ๋ฆผ์„ ์ฃผ๊ธฐ ์œ„ํ•œ ์šฉ๋„ ์ด์™ธ์—๋Š” ์‚ฌ์šฉํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

์œ„ ์ฝ”๋“œ์—์„œ Set ํ–ˆ์„ ๋•Œ Update ํ–ˆ์Œ์„ ์•Œ๋ฆฐ๋‹ค๋ฉด StrTest ๊ฐ’ ๋ณ€๊ฒฝ ์‹œ ์ฒ˜๋ฆฌํ•  ์ž‘์—…์ด IntTest ์•Œ๋ฆผ์ผ ๋•Œ๋„ ํ˜ธ์ถœํ•˜๊ธฐ ๋•Œ๋ฌธ์— Binding ๋œ Property๊ฐ€ ๋งŽ๋‹ค๋ฉด ๋ถˆํ•„์š”ํ•œ ๋น„์šฉ์ด ๋งŽ์ด ๋ฐœ์ƒํ•  ๊ฒƒ ๊ฐ™์•„์š”.
๋ณดํ†ต์€ UI ์“ฐ๋ ˆ๋“œ์—์„œ ์ด๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š”๋ฐ ๋น„์šฉ์ด ํฐ ์ž‘์—…์ด ํฌํ•จ๋๊ฑฐ๋‚˜ ๋นˆ๋ฒˆํžˆ ํ˜ธ์ถœ๋  ๊ฒฝ์šฐ ์‚ฌ์šฉ์ž๊ฐ€ ๋ดค์„ ๋•Œ ํ™”๋ฉด์ด ๋ฒ„๋ฒ…์ด๋Š” ๋Š๋‚Œ์„ ๋ฐ›์„ ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์•„์š”.

์ด๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด์„œ ์ €๋Š” setter ๋‚ด๋ถ€์— ํ•„์š”ํ•œ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•˜๊ฑฐ๋‚˜ ํ•„์š”ํ•œ ๊ธฐ๋Šฅ์ด ๊ตฌํ˜„๋œ ํ•จ์ˆ˜๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ ํ•ด๊ฒฐํ•ฉ๋‹ˆ๋‹ค.
๋น„์šฉ์ด ํฐ ๊ฑด์ด ์žˆ๋‹ค๋ฉด ๋น„๋™๊ธฐ ์ž‘์—…์„ ์ถ”๊ฐ€ํ•˜๊ธฐ๋„ ํ•ฉ๋‹ˆ๋‹ค.

๋ฌผ๋ก  ์œ„ ๋‚ด์šฉ์€ ์ œ ๊ฐœ์ธ์ ์ธ ์Šต๊ด€(?)์ž…๋‹ˆ๋‹ค :slight_smile:

์ข‹์•„์š” 3

Property๊ฐ€ ๋ฐ”๋€”๋•Œ๋งˆ๋‹ค ํ˜ธ์ถœ๋˜๊ธฐ๋•Œ๋ฌธ์— level๋‹˜ ๋ง์”€ํ•˜์‹ ๊ฑฐ ์ถฉ๋ถ„ํžˆ ๊ณต๊ฐํ•ฉ๋‹ˆ๋‹ค.
ํ•˜์ง€๋งŒ ๊ฐœ์ธ์ ์œผ๋กœ๋Š” Property Set๋‚ด๋ถ€์— ์ฝ”๋”ฉํ•˜๋Š”๊ฑธ ์•ˆ์ข‹์•„ ํ•˜๋Š”์ง€๋ผโ€ฆใ…Žใ…Ž;
Set์— ์ฝ”๋”ฉํ•ด๋†“์œผ๋ฉด ๋ถ„์„ํ• ๋•Œ ํž˜๋“ค๋”๋ผ๊ณ ์š”โ€ฆ Property๋Š” ๊ฐ€๊ธ‰์ ์ด๋ฉด ์„ ์–ธ ๋ฐ ์ดˆ๊ธฐ๊ฐ’ ์„ธํŒ…๋งŒโ€ฆ
๊ทธ๋ฆฌ๊ณ  ๋‚˜์ค‘์— ํ”„๋กœํผํ‹ฐ๊ฐ€ ๋งŽ์•„์ง€๋ฉด ์œ ์ง€๋ณด์ˆ˜ ์ธก๋ฉด์—์„œ๋„ PropertyChanged ํ•œ๊ณณ๋งŒ ๋ณด๋ฉด๋˜์„œ ๊ด€๋ฆฌ๊ฐ€ ํŽธํ•ด์ง‘๋‹ˆ๋‹ค.
์ €๋Š” ๊ฐ€๋…์„ฑ์ด ์ข‹๊ณ  ์œ ์ง€๋ณด์ˆ˜๊ฐ€ ํŽธํ•œ ์ฝ”๋“œ๊ฐ€ ์ข‹๋”๋ผ๊ณ ์š”

์ข‹์•„์š” 3

์ œ๊ฐ€ ๊ณ„์†ํ•ด์„œ ๊ฐœ๋ฐœํ•ด ์˜ค๋Š” ๋‘๊ฐ€์ง€ WPF ์žˆ์Šต๋‹ˆ๋‹ค. ํ•˜๋‚˜๋Š” ๋น„๋””์˜ค/์˜ค๋””์˜ค ํ”„๋กœ์„ธ์‹ฑ (60 Hz ์ดˆ๋‹น) ๋˜ ํ•˜๋‚˜๋Š” ํŒจํ‚ท๋ ˆ๋ฒŒ ํ”„๋กœ์„ธ์‹ฑ (๋งŽ๊ฒŒ๋Š” ์ดˆ๋‹น 160 Mbps) ์ •๋„ ๋ฉ๋‹ˆ๋‹ค. ๋งŽ์€ ๋ฐ์ดํƒ€ ์ฒ˜๋ฆฌ์™€ ํ•จ๊ป˜ ๋ชจ๋“  ๋ฐ์ดํƒ€ ๋ณ€ํ™”๋ฅผ ๋ณด์—ฌ์ฃผ์—ฌ์•ผ ํ•˜๊ธฐ์— INotifyPropertyChanged ๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์œผ๋‚˜ ๋ถˆํ•„์š”ํ•œ ๋น„์šฉ์€ ์ƒ๊ธฐ์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ์ €์˜ ํŒ€์˜ ๊ฒฝ์šฐ์—๋Š” ์ ˆ๋Œ€๋กœ ๋ทฐ์™€ ๋ทฐ๋ชจ๋ธ์— ์–ด๋– ํ•œ ๋กœ์ง์ด๋‚˜ ์ฝ”๋“œ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. ์˜ค์ง INotifyPropertyChanged ์™€ get / set ๋ฟ์ด๊ณ  ๋ชจ๋“  ์ฒ˜๋ฆฌ๋Š” ๋ชจ๋ธ์—์„œ ์ด๋ฃจ์–ด ์ง‘๋‹ˆ๋‹ค. ๊ทธ๋ž˜์„œ Blazor ์ž‘์—…ํ• ๋•Œ๋„ ์ˆ˜์›”ํ•˜๊ฒŒ ํ• ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

์ข‹์•„์š” 3