How to Bind to a Custom Controls Button Visibility from Within Another Control

前端 未结 3 1268
后悔当初
后悔当初 2021-01-19 03:38

I have a custom control, which has a button:



        
3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-19 04:10

    Hi just create a bool or Visibility Type property in UserControl1 and set it in Usercontrol2 like

    UserControl1 xaml

    
    
        

    xaml.cs

     public UserControl1()
        {
            InitializeComponent();
        }
    
        bool showLoadButton;
        public bool ShowLoadButton
        {
            get { return showLoadButton; }
            set
            {
                showLoadButton = value;
                if (showLoadButton)
                    Loadbutton.Visibility = Visibility.Visible;
                else
                    Loadbutton.Visibility = Visibility.Collapsed;
            }
    
        }
    

    UserControl2 Set ShowLoadButton True or false

    
    
        
    
    

提交回复
热议问题