“AttachedProperty” PropertyChangedCallback never calls for my LayoutAnchorable, but works on DockingManager. AvalonDock

蹲街弑〆低调 提交于 2020-01-07 06:15:35

问题


I am trying to use AttachedProperty in my AvalonDock, I want it to be part of LayoutAnchorable but PropertyChangedCallback never get called. i have binded AttachedPropert and i am getting the control over ViewModel ie: when binded property changes it trigger my ViewModel Property.

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>

ViewModel Property

    private bool _IsHideExplorer;
    public bool IsHideExplorer 
    {
        get { return _IsHideExplorer; }
        set { _IsHideExplorer = value; NotifyPropertyChanged(); }
    }

I have tried attaching the property to DockingManager the PropertyChangedCallback works. Any Help guys.


回答1:


Did you already check the DataContext of your LayoutAnchorable? Maybe the DataContext is not passed down to it. In that case the Binding would not work and your DependencyProperty is not updated.



来源:https://stackoverflow.com/questions/32357350/attachedproperty-propertychangedcallback-never-calls-for-my-layoutanchorable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!