"AttachedProperty" PropertyChangedCallback 从不调用我的 LayoutAnchorable,而是在 DockingManager 上工作。阿瓦隆码头



我试图在我的AvalonDock中使用AttachedProperty,我希望它成为LayoutAnchorable的一部分,但PropertyChangedCallback从未被调用。我已经绑定了AttachedPropert,我正在控制ViewModel即:当绑定属性改变时,它会触发我的ViewModel属性。

My AttachedProperty

public static readonly DependencyProperty IsCanVisibleProperty =
        DependencyProperty.RegisterAttached("IsCanVisible", typeof(bool), typeof(AvalonDockBehaviour), new FrameworkPropertyMetadata(new PropertyChangedCallback(IsCanVisiblePropertyChanged)));
    private static void IsCanVisiblePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        LayoutAnchorable control = d as LayoutAnchorable;
        if (control != null)
        {
            control.IsVisible = (bool)e.NewValue;
        }
    }
    public static void SetIsCanVisible(DependencyObject element, bool value)
    {   
        element.SetValue(IsCanVisibleProperty, value);
    }
    public static bool GetIsCanVisible(DependencyObject element)
    {
        return (bool)element.GetValue(IsCanVisibleProperty);
    }

XAML

  <xcad:DockingManager>               
     <xcad:LayoutRoot >                 
        <xcad:LayoutPanel Orientation="Horizontal" >       
            <xcad:LayoutAnchorablePane >                                
                  <xcad:LayoutAnchorable Title="Folder" behv:AvalonDockBehaviour.IsCanVisible="{Binding IsHideExplorer, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">
                       <Views:ExplorerView DataContext="{Binding ExplorerViewModel}"/>
                  </xcad:LayoutAnchorable>
            </xcad:LayoutAnchorablePane>
        </xcad:LayoutPanel>
      </xcad:LayoutRoot>
  </xcad:DockingManager>
<<p> ViewModel属性/strong>
    private bool _IsHideExplorer;
    public bool IsHideExplorer 
    {
        get { return _IsHideExplorer; }
        set { _IsHideExplorer = value; NotifyPropertyChanged(); }
    }

我已经尝试将属性附加到DockingManager PropertyChangedCallback的作品。

您是否已经检查了您的LayoutAnchorable的DataContext ?也许DataContext没有传递给它。在这种情况下,绑定将无法工作,并且您的DependencyProperty不会更新。

最新更新