" AttachedProperty" PropertyChangedCallback从不调用我的LayoutAnchorable,但在DockingManager上工作。 AvalonDock

时间:2015-09-02 15:34:25

标签: c# wpf mvvm attached-properties avalondock

我想在我的AvalonDock中使用AttachedProperty,我希望它成为LayoutAnchorable的一部分,但PropertyChangedCallback永远不会被调用。我已绑定AttachedPropert,我可以控制ViewModel,即:当绑定属性更改时,它会触发我的ViewModel属性。

我的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属性

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

我已尝试将该属性附加到DockingManager PropertyChangedCallback作品。任何帮助人员。

1 个答案:

答案 0 :(得分:-1)

您是否已经检查过LayoutAnchorable的DataContext?也许DataContext没有传递给它。在这种情况下,Binding将不起作用,并且您的DependencyProperty不会更新。