外部设置UI上control的Visibility,一般会在property里进行设置,例如:
![ContractedBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 public Visibility CancelButtonVisibility{
2 get{
3 return this.btnCancel.Visibility;
4 }
5 set{
6 this.btnCancel.Visibility = value;
7 }
8 }
这样在property中直接拿control不太好。有另一种方法会好点:
![ContractedBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 private Boolean _isCancellable = false;
2
3 //Get/Set IsCancellable property
4 public Boolean IsCancellable{
5 get{
6 return this._isCancellable;
7 }
8 set{
9 this._isCancellable = value;
10 this.OnIsCancellableChanged();
11 }
12 }
13
14 protected virtual void OnIsCancellableChanged() {
15 if(this.IsCancellable){
16 this.btnCancel.Visibility = Visibility.Visible;
17 }else{
18 this.btnCancel.Visibility = Visibility.Collapsed;
19 }
20 }