“AttachedProperty"PropertyChangedCallback从不调用我的LayoutAn

本文关键字:调用 我的 LayoutAn PropertyChangedCallback AttachedProperty quot | 更新日期: 2023-09-27 18:11:04

我试图在我的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的作品。

“AttachedProperty"PropertyChangedCallback从不调用我的LayoutAn

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