简体   繁体   English

AvalonDock:动态改变 LayoutAnchorablePane 的 CanClose 属性

[英]AvalonDock: Dynamically changing LayoutAnchorablePane's CanClose property

In AvalonDock, is it possible to modify a LayoutAnchorablePane 's CanClose property dynamically at runtime?在 AvalonDock 中,是否可以在运行时动态修改LayoutAnchorablePaneCanClose属性? I would like to prevent/lock layout changes unless the user specifically desires to do so and turns it on.我想阻止/锁定布局更改,除非用户特别希望这样做并打开它。

I have tried the following approaches:我尝试了以下方法:

  1. Binding: It is not possible to bind the property because it is not a DependencyProperty so something like this doesn't work: <dock:LayoutAnchorable CanClose="{Binding CanClose}">绑定:无法绑定属性,因为它不是DependencyProperty ,所以这样的东西不起作用: <dock:LayoutAnchorable CanClose="{Binding CanClose}">
  2. CanClose property: Changing the LayoutAnchorablePane 's CanClose property in code-behind is not possible because the property is read-only. CanClose属性:无法在代码隐藏中更改LayoutAnchorablePaneCanClose属性,因为该属性是只读的。

According to the source code of LayoutAnchorablePane :根据LayoutAnchorablePane的源代码:

#region CanClose

public bool CanClose
{
  get
  {
    return Children.All( a => a.CanClose );
  }
}

#endregion

the CanClose property depends on all children of the pane, so one way to change the value of CanClose of a LayoutAnchorablePane is to set all its children's CanClose property to the value you want. CanClose属性取决于窗格的所有子级,因此更改CanCloseLayoutAnchorablePane值的一种方法是将其所有子级的CanClose属性设置为所需的值。 Below is an example:下面是一个例子:

...
foreach(var child in pane.Children)
{
    child.CanClose = true; // or false.
}
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM