WPF user control, access dependency properties of component elements

前端 未结 2 468
南笙
南笙 2021-01-22 17:14

Problem

A user WPF control is made up of multiple standard controls.

How can multiple dependency properties of the component (base or standard) controls be acc

2条回答
  •  长发绾君心
    2021-01-22 17:53

    The way you suggested - I don't think this would be possible. But it can be done with normal properties, instead of dependency properties, something like:

    UserControl xaml:

    
        
        
    
    

    UserControl code behind:

        public string One
        {
            get
            {
                return this.tbOne.Text;
            }
            set
            {
                this.tbOne.Text = value;
            }
        }
    
        public string Two
        {
            get
            {
                return this.tbTwo.Text;
            }
            set
            {
                this.tbTwo.Text = value;
            }
        }
    

    and the usage of user control:

        
    

提交回复
热议问题