wpf2023. 6. 9. 18:37

 private void MessageCheck_Checked(object sender, RoutedEventArgs e)
        {
            if (IsLoaded == false)
                return;

            var name = (sender as ToggleButton).Name;

            var ctl = xGroups.FindName(name) as ToggleButton;

            DataManager.LocalData.MessageSelect.GetType().GetProperty(name.Remove(0, 1)).SetValue(DataManager.LocalData.MessageSelect, ctl.IsChecked);

            DataManager.Instance.SaveData();
        }

        private void TelegramMessageSelectPage_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if ((e.NewValue) as bool? == false)
                return;

            foreach (var item in DataManager.LocalData.MessageSelect.GetType().GetProperties())
            {
                var ctl = xGroups.FindName($"x{item.Name}") as ToggleButton;

                if (ctl != null)
                    ctl.IsChecked = (bool)item.GetValue(DataManager.LocalData.MessageSelect);
            }
        }

 

 public class MessageSelectModel
    {
        public bool IsDeepSleep { get; set; }

        public bool IsStartEndMap { get; set; }

        public bool IsDriveEnd { get; set; }
    }

 

 

 

그냥 바인딩하는게 최고지만 피지 못할경우에는 

 xIsAutoAfterBlowBtn.IsChecked = DataManager.LocalData.IsAutoAfterBlow; <-이런식으로 노가다 작업하지말고

 

xName이랑 프로퍼티랑 이름을 같게해서 반복작업을 줄여보자

Posted by 동동(이재동)