2015-09-02 9 views
0

我想在我的AvalonDock中使用AttachedProperty,我希望它成为LayoutAnchorable的一部分,但PropertyChangedCallback永远不会被调用。我已经绑定AttachedPropert,并且我得到了对ViewModel的控制,即:当绑定属性更改时,它会触发我的ViewModel属性。“AttachedProperty”PropertyChangedCallback永远不会调用我的LayoutAnchorable,但可用于DockingManager。 AvalonDock

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> 

视图模型属性

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

我曾尝试将该物业附于DockingManagerPropertyChangedCallback作品。任何帮助家伙。

回答

-1

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

相关问题