关闭或隐藏LayoutAnchorableItem行为是什么?如何以编程方式与之交互?

时间:2019-02-01 15:03:44

标签: c# wpf avalondock

我已经在功能区菜单后面实现了AvalonDock接口。尽管有Internet上的文档,但我对LayoutAnchorableItem的编程工作方式不太了解。

这困扰着我达到我的目标: 我想要一个RibbonTab调用“视图”,在其中可以选择要打开哪个窗口(有点像Visual Studio中的“视图”菜单)。这些Windows中的一些是可锚定项目。通过将其添加到我的可锚定项目列表中,我成功打开了该窗口,但是如何通知该窗口是否已在屏幕上打开(因此,可锚定变为“选定”,“活动”并退出该过程)或是否已隐藏(等等) ,将其添加到我的固定列表中并打开它)?

我尝试实现“可见性”属性,但是没有任何反应,当我执行应用程序时单击“隐藏”按钮时,该属性没有更改。

我的XAML代码如下:

    <dock:DockingManager AllowMixedOrientation="True" DataContext="{Binding DockManagerViewModel}" DocumentsSource="{Binding Documents}" AnchorablesSource="{Binding Anchorables}" >
        <dock:DockingManager.LayoutItemContainerStyleSelector>
             <style:PanesStyleSelector DefaultStyle="{StaticResource DefaultStyle}" CustomStyle="{StaticResource CustomStyle}"/>
</dock:DockingManager.LayoutItemContainerStyleSelector>
        <dock:LayoutRoot >
               <dock:LayoutPanel Orientation="Vertical">
               <dock:LayoutDocumentPaneGroup>
                     <dock:LayoutDocumentPane />
               </dock:LayoutDocumentPaneGroup>
               <dock:LayoutAnchorablePaneGroup DockMinHeight="250" FloatingHeight="250">
                    <dock:LayoutAnchorablePane />
               </dock:LayoutAnchorablePaneGroup>
           </dock:LayoutPanel>
        </dock:LayoutRoot>
    </dock:DockingManager>

我的PaneStyleSelector类是: 公共样式DefaultStyle {get;组; }         公共样式CustomStyle {get;组; }

    public override Style SelectStyle(object item, DependencyObject container)
    {
        if (item is LayoutAnchorableItem)
        {
            return CustomStyle;
        }
        return DefaultStyle;
    }

我的ResourceDictionary是:

<Style TargetType="{x:Type dockctrl:LayoutItem}" x:Key="DefaultStyle">
        <Setter Property="Title" Value="{Binding Model.Title}" />
        <Setter Property="CloseCommand" Value="{Binding Model.CloseCommand}" />
        <Setter Property="CanClose" Value="{Binding Model.CanClose}" />
        <Setter Property="IsSelected" Value="{Binding Model.IsSelected}" />
    </Style>
    <dock:BoolToVisibilityConverter x:Key="btvc"/>
    <Style TargetType="{x:Type dockctrl:LayoutAnchorableItem}" BasedOn="{StaticResource DefaultStyle}" x:Key="CustomStyle">
        <Setter Property="Visibility" Value="{Binding Model.IsVisible, ConverterParameter={x:Static Visibility.Hidden}, Converter={StaticResource btvc}, Mode=TwoWay}"/>
    </Style>

Anchorables是一个ObservableCollection,其中AnchorWindowViewModel具有以下属性:

private bool _Visibility;
    public bool Visibility
    {
        get { return _Visibility; }
        set
        {
            if (_Visibility != value)
            {
                _Visibility = value;
                OnPropertyChanged(nameof(Visibility));
            }
        }
    }

0 个答案:

没有答案