using System.Windows;
using System.Windows.Data;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.Data.DataForm;

namespace DataFormBugDemo
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {

        public MainWindow()
        {
            StyleManager.ApplicationTheme = new Office2019Theme();
            Office2019Palette.LoadPreset(Office2019Palette.ColorVariation.Dark);
            InitializeComponent();
        }

        private void RadDataForm_OnAutoGeneratingField(object sender, AutoGeneratingFieldEventArgs e)
        {
            e.DataField.DataMemberBinding.NotifyOnSourceUpdated = true;
            e.DataField.DataMemberBinding.NotifyOnValidationError = true;
            e.DataField.DataMemberBinding.ValidatesOnDataErrors = true;
            e.DataField.DataMemberBinding.ValidatesOnNotifyDataErrors = true;
            e.DataField.DataMemberBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
            if (e.PropertyType == typeof(HotKey))
            {
                var dataField = new DataFormHotKeySettingsField()
                {
                    Label = e.DataField.Label,
                    DataMemberBinding = e.DataField.DataMemberBinding,
                    Description = e.DataField.Description
                };
                e.DataField = dataField;
            }
        }
    }
}
