C# 在Avalon Dock中,如何以编程方式隐藏LayoutDocumentPane项并将其还原
我正在使用上下文菜单上的devexpress,试图隐藏根面板中存在的许多LayoutDocument之一 下面是documentpane xml文件C# 在Avalon Dock中,如何以编程方式隐藏LayoutDocumentPane项并将其还原,c#,wpf,mvvm,devexpress,avalondock,C#,Wpf,Mvvm,Devexpress,Avalondock,我正在使用上下文菜单上的devexpress,试图隐藏根面板中存在的许多LayoutDocument之一 下面是documentpane xml文件 <LayoutDocumentPane> <LayoutDocument Title=" View " IsSelected="True" ContentId="view" CanClose="False" LastActivationTimeStamp="10/15/2018 12:17:44" />
<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>
经过大量的调试和搜索,我还没有找到任何解决方案,如何隐藏dock面板并在单击某个按钮时还原它们。您可以切换
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>
我在尝试了很多尝试错误很多天后找到了一种方法
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;
.......................
}
}
private void BarbuttonItemClick(对象发送者,DevExpress.Xpf.bar.ItemClickEventArgs e)
{
字符串currentDockPane=e.Item.Content.ToString();
开关(currentDockPane)
{
案例“视图”:
var currentLayout=StandardDockManager.Layout.degents().OfType()。其中(x=>x.ContentId==“视图”).FirstOrDefault();
//获取当前dock manger的所有后代,并检查LayoutAchorable(如果可见)。
如果(currentLayout.IsVisible)
(((Xceed.Wpf.AvalonDock.Layout.layoutunachrable)(currentLayout)).IsVisible=false;
其他的
(((Xceed.Wpf.AvalonDock.Layout.layoutunathrable)(currentLayout)).IsVisible=true;
打破
.......................
}
}
您能详细解释一下吗?