В доке Авалон, Как программно скрыть элемент LayoutDocumentPane, а также восстановить их - PullRequest
0 голосов
/ 18 октября 2018

Я использую devexpress, в контекстном меню пытаюсь скрыть один из множества LayoutDocument, присутствующих в RootPanel.

Ниже приведен XML-файл панели документов.

  <LayoutDocumentPane>
        <LayoutDocument Title="  View  " IsSelected="True" ContentId="view" CanClose="False" LastActivationTimeStamp="10/15/2018 12:17:44" />
      </LayoutDocumentPane>

Ниже приведенКод Xaml

  <xcad:LayoutDocument Title="  View  "  CanClose="False"  ContentId="View"  >
        <dxg:GridControl Name="dataTable" EnableSmartColumnsGeneration="True" 
                         ItemsSource="{Binding View_InfoTable,Mode=TwoWay,NotifyOnSourceUpdated=True,NotifyOnTargetUpdated=True}" SelectionMode="Row" 
                         AutoGenerateColumns="AddNew"  AllowColumnMRUFilterList="True"  ShowAllTableValuesInFilterPopup="False">
            <dxg:GridControl.View>
                <dxg:TableView ShowAutoFilterRow="True"  UseGroupShadowIndent="False" ShowGroupPanel="False" ShowCriteriaInAutoFilterRow="True" AllowSorting="False" BestFitMode="VisibleRows" 
                               ShowFixedTotalSummary="False" >
                </dxg:TableView>
            </dxg:GridControl.View>
        </dxg:GridControl>
 </xcad:LayoutDocument>

После долгих отладок и поиска у меня нет решения, как скрыть панель док-станции и восстановить ее, нажав на какую-нибудь кнопку.

Ответы [ 2 ]

0 голосов
/ 30 ноября 2018

Я нашел способ после многократных пробных ошибок в течение многих дней.

 private void BarButtonItem_ItemClick(object sender, DevExpress.Xpf.Bars.ItemClickEventArgs e)
     {
     string currentDockPane = e.Item.Content.ToString();       
      switch (currentDockPane)
          {
            case "view":
           var currentLayout= StandardDockManager.Layout.Descendents().OfType<LayoutAnchorable>().Where(x => x.ContentId == "view").FirstOrDefault();
     //Get all the descendents of current dock manger and check for the LayoutAnchorable if its visible .
                if (currentLayout.IsVisible)
               (((Xceed.Wpf.AvalonDock.Layout.LayoutAnchorable)(currentLayout))).IsVisible = false;
                             else
               (((Xceed.Wpf.AvalonDock.Layout.LayoutAnchorable)(currentLayout))).IsVisible = true;
            break;
              .......................
        }
    }
0 голосов
/ 18 октября 2018

Вы можете переключать свойство Visibility LayoutDocumentPane

<Style TargetType="{x:Type xcad:LayoutItem}">
    <Setter Property="Visibility" Value="{Binding Model.IsVisible, Mode=TwoWay, Converter={StaticResource BoolToVisibilityConverter}}" />
</Style>

Вот как я это сделал с имплементацией MVVM.

проверьте, что стиль, который я дал для стиля файла и стиля панели инструментов, имеет свойство видимости, связанное, поэтому мы можем использовать ViewModel для переключения видимости.

<xcad:DockingManager
    x:Name="DockingManagerDockView"
    ActiveContent="{Binding ActiveToolsPane, Mode=TwoWay}"
    AnchorablesSource="{Binding AnchorableSource}"
    DocumentsSource="{Binding DocumentSource}">
    <xcad:DockingManager.LayoutUpdateStrategy>
        <Pane:LayoutInitializer />
    </xcad:DockingManager.LayoutUpdateStrategy>
    <xcad:DockingManager.Resources>
        <DataTemplate DataType="{x:Type ViewModels:ExplorerViewModel}">
            <Views:ExplorerView />
        </DataTemplate>
        <Style TargetType="avalonDockControls:AnchorablePaneTitle">
            <Setter Property="BorderThickness" Value="0"/>
        </Style>
    </xcad:DockingManager.Resources>
    <xcad:DockingManager.AnchorableTitleTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <Image Margin="2" Source="{Binding IconSource}" />
                <TextBlock
                    FontSize="12"
                    FontWeight="Bold"
                    Text="{Binding Title}" />
            </StackPanel>
        </DataTemplate>
    </xcad:DockingManager.AnchorableTitleTemplate>

    <xcad:DockingManager.AnchorableHeaderTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <Image Margin="2" Source="{Binding IconSource}" />
                <TextBlock
                    FontSize="12"
                    FontWeight="Bold"
                    Text="{Binding Title}" />
            </StackPanel>
        </DataTemplate>
    </xcad:DockingManager.AnchorableHeaderTemplate>
    <xcad:DockingManager.DocumentHeaderTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <Image Source="{Binding IconSource}" />
                <TextBlock
                    FontSize="12"
                    FontWeight="Bold"
                    Text="{Binding Title}" />
            </StackPanel>
        </DataTemplate>
    </xcad:DockingManager.DocumentHeaderTemplate>
    <xcad:DockingManager.LayoutItemContainerStyleSelector>
        <Pane:PanesStyleSelector>
            <Pane:PanesStyleSelector.ToolStyle>
                <Style TargetType="{x:Type xcad:LayoutAnchorableItem}">                        
                    <Setter Property="Visibility" Value="{Binding Model.IsVisible, Mode=TwoWay, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter={x:Static Visibility.Hidden}}" />
                    <Setter Property="ContentId" Value="{Binding Model.ContentId}" />
                    <Setter Property="FlowDirection" Value="RightToLeft" />
                    <Setter Property="UseLayoutRounding" Value="False" />
                    <Setter Property="IconSource" Value="{Binding Model.IconSource}" />
                    <Setter Property="IsHitTestVisible" Value="True" />
                    <Setter Property="Title" Value="{Binding Model.Title}" />
                </Style>
            </Pane:PanesStyleSelector.ToolStyle>
            <Pane:PanesStyleSelector.FileStyle>
              <Style TargetType="{x:Type xcad:LayoutItem}">
                    <Setter Property="Visibility" Value="{Binding Model.IsVisible, Mode=TwoWay, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter={x:Static Visibility.Hidden}}" />                    
                    <Setter Property="Title" Value="{Binding Model.Title}" />
                    <Setter Property="ContentId" Value="{Binding Model.ContentId}" />
                    <Setter Property="CanClose" Value="{Binding Model.CanClose}" />
                    <Setter Property="IconSource" Value="{Binding Model.IconSource}" />
                    <Setter Property="CanFloat" Value="{Binding Model.CanFloat}" />
                    <Setter Property="Margin" Value="5" />
                </Style>
            </Pane:PanesStyleSelector.FileStyle>
        </Pane:PanesStyleSelector>
    </xcad:DockingManager.LayoutItemContainerStyleSelector>
    <xcad:LayoutRoot>
        <xcad:LayoutPanel>
            <xcad:LayoutDocumentPane />
            <xcad:LayoutAnchorablePane Name="Explorer" />                
        </xcad:LayoutPanel>
    </xcad:LayoutRoot>
  </xcad:LayoutRoot>
</xcad:DockingManager>
...