Order In Chaos Of Control Initialization Steps

后端 未结 2 1390
野趣味
野趣味 2021-01-17 02:12

I would like to know when is actually what happening inside initalization process of controls when I start a WPF application?

When are DP initalized? When Binding? W

2条回答
  •  我在风中等你
    2021-01-17 02:50

    In WPF you are setting default values for DP with PropertyMetaData not via constructor.

    public partial class UserControl1 : ContentControl
    {
        public UserControl1()
        {
            InitializeComponent();
        }
    
        public string TestDependencyProperty
        {
            get { return (string)GetValue(TestDependencyPropertyProperty); }
            set { SetValue(TestDependencyPropertyProperty, value); }
        }
    
        public static DependencyProperty TestDependencyPropertyProperty =
            DependencyProperty.Register("TestDependencyProperty", typeof(string), typeof(UserControl1), 
            new PropertyMetadata("234"));
    }
    

提交回复
热议问题