Wpf 如何在使用MVVM时禁用对LayoutAchorable的隐藏

Wpf 如何在使用MVVM时禁用对LayoutAchorable的隐藏,wpf,mvvm,avalondock,Wpf,Mvvm,Avalondock,我正在尝试将AvalonDock与MVVM结合使用,并禁用layoutAchorable的隐藏功能。如果没有MVVM,我可以执行以下操作: <xcad:LayoutAnchorable CanHide="False"> <TextBox>Some Content</TextBox> </xcad:LayoutAnchorable> 还有一个非常简单的模型类: public class UserPanel : INotifyPropertyCh

我正在尝试将AvalonDock与MVVM结合使用,并禁用
layoutAchorable
的隐藏功能。如果没有MVVM,我可以执行以下操作:

<xcad:LayoutAnchorable CanHide="False">
  <TextBox>Some Content</TextBox>
</xcad:LayoutAnchorable>
还有一个非常简单的模型类:

public class UserPanel : INotifyPropertyChanged
{
  public string Title { get; set; }
  public string ContentId { get; set; }
  public bool CanHide { get; set; }         // ??
  // (NotifyPropertyChanged not implemented for these properties here
  // for the sake of brevity. Basically works without.)

  public UserControl Control
  {
    get => _userInterface;
    set
    {
      if (value != _userInterface)
      {
        _userInterface = value;
        OnPropertyChanged();
      }
    }
  }
  UserControl _userInterface;

  public event PropertyChangedEventHandler PropertyChanged;

  void OnPropertyChanged([CallerMemberName] string propertyName = null)
  {
    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  }
}
视图类是从绑定的
UserPanelList
的内容创建的


但是,
LayoutItem
类不包含
CanHide
属性,即我不能使用
afaik。我能做些什么呢?

LayoutItem
派生的类
layoutChrableItem
用于
layoutChrable
s(请参阅)。它有一个依赖属性
CanHide
,可以按预期工作

On可以通过以下两种方式设置
layoutAchrableItem
的样式

<Style TargetType="xcad:LayoutAnchorableItem">
  <!-- ... -->
  <Setter Property="CanHide" Value="{Binding Model.CanHide}" />

或者,更灵活地说,通过

<Style TargetType="xcad:LayoutItem">
  <!-- ... -->
  <Setter Property="xcad:LayoutAnchorableItem.CanHide" Value="{Binding Model.CanHide}" />


就在旁边。只需在CanHide上应用INotifyPropertyChanged布尔值,就像在控件上所做的一样UserControl@NawedNabiZada没有
。AvalonDock通过
AnchorablesSource=“{Binding UserPanelList}”
UserPanelList
绑定的内容创建
LayoutAcrobles
。这就是我使用
s的原因。您是否也能找到禁用“自动隐藏”的方法?隐藏只会去掉“x”并留下“pin符号”@CM0491我没有考虑禁用自动隐藏。有一个
layoutachrable.CanAutoHide
,但在
LayoutItem
或派生类中似乎没有
CanAutoHide
属性——目前,我不知道如何做。
<Style TargetType="xcad:LayoutItem">
  <!-- ... -->
  <Setter Property="xcad:LayoutAnchorableItem.CanHide" Value="{Binding Model.CanHide}" />