我有一个使用 Xceed Avalon Dock 2.0 的 .NET 6.0 程序。我将“AnchorableSource”设置为 ViewModel 的
BindableCollection
,并且当前集合中只有一个视图模型。我的问题是,当我自动隐藏面板时,它会折叠到底部,但当我单击标题时它不会重新打开。
折叠为:
但是当我单击“工具”时没有任何反应。
我不确定在哪里放置断点,或者是否可以在后面添加一些代码来捕获单击并重新打开。 我有另一个项目使用相同的东西,并且它重新打开得很好。
这是我的代码:
MainView.xaml
<Controls:MetroWindow x:Class="GUI.Core.Views.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
xmlns:cal="http://caliburnmicro.com"
xmlns:avalonDock="http://schemas.xceed.com/wpf/xaml/avalondock"
xmlns:avalonDock1="clr-namespace:GUI.Resources"
xmlns:viewmodels="clr-namespace:GUI.Core.ViewModels"
d:DataContext="{d:DesignInstance Type=viewmodels:MainViewModel}"
Icon="pack://application:,,,/Resources/Images/Icon.png"
mc:Ignorable="d"
Title="GUI" HorizontalAlignment="Center" VerticalAlignment="Center" AllowsTransparency="True" WindowStyle="None" IsManipulationEnabled="True" SaveWindowPosition="True">
<Grid Margin="0 0 0 5">
<Grid.Background>
<ImageBrush ImageSource="pack://application:,,,/Resources/Images/BGPATTERN.png" TileMode="Tile" Stretch="UniformToFill" />
</Grid.Background>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" CanContentScroll="True">
<StackPanel Orientation="Horizontal" FlowDirection="LeftToRight" Background="{StaticResource MenuBrush}" CanVerticallyScroll="True" CanHorizontallyScroll="True" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="True">
<TextBlock Style="{StaticResource MenuTextStyle}" cal:Message.Attach="[Event MouseDown] = [Action MenuItemClick('ModeSelection')]" Text="Mode Selection" />
<TextBlock Margin="3" Foreground="White" Opacity="0.5" Text="|" />
<TextBlock Style="{StaticResource MenuTextStyle}" cal:Message.Attach="[Event MouseDown] = [Action MenuItemClick('Load')]" Text="Load" />
<TextBlock Margin="3" Foreground="White" Opacity="0.5" Text="|" />
<TextBlock Style="{StaticResource MenuTextStyle}" cal:Message.Attach="[Event MouseDown] = [Action MenuItemClick('FaultLog')]" Text="Fault Log" />
<TextBlock Margin="3" Foreground="White" Opacity="0.5" Text="|" />
<TextBlock Style="{StaticResource MenuTextStyle}" cal:Message.Attach="[Event MouseDown] = [Action MenuItemClick('Health')]" Text="Health" />
</StackPanel>
</ScrollViewer>
<avalonDock:DockingManager x:Name="dockingManager"
cal:Message.Attach="[Event DocumentClosing] = [Action DocumentClosingListener($eventArgs)];
[Event DocumentClosed] = [Action DocumentClosedListener()]"
AnchorablesSource="{Binding Tools}"
DocumentsSource="{Binding Documents}"
ActiveContent="{Binding ActiveDocument, Mode=TwoWay}"
Grid.Row="1" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="True" FontFamily="Calibri" FontSize="14" Background="{x:Null}" SnapsToDevicePixels="True" ClipToBounds="True" Margin="0 0 3 0">
<avalonDock:DockingManager.Theme>
<avalonDock:MetroTheme />
</avalonDock:DockingManager.Theme>
<avalonDock:DockingManager.LayoutItemContainerStyle>
<Style TargetType="{x:Type avalonDock:LayoutItem}">
<Setter Property="CanClose" Value="{Binding Model.CanClose, Mode=TwoWay}" />
<Setter Property="Title" Value="{Binding Model.Title}" />
<Setter Property="IsActive" Value="{Binding Model.IsActive, Mode=TwoWay}" />
<Setter Property="Visibility" Value="Visible" />
</Style>
</avalonDock:DockingManager.LayoutItemContainerStyle>
<avalonDock:DockingManager.LayoutItemTemplateSelector>
<avalonDock1:AutobinderTemplateSelector>
<avalonDock1:AutobinderTemplateSelector.Template>
<DataTemplate>
<ContentControl cal:View.Model="{Binding . }" IsTabStop="False" />
</DataTemplate>
</avalonDock1:AutobinderTemplateSelector.Template>
</avalonDock1:AutobinderTemplateSelector>
</avalonDock:DockingManager.LayoutItemTemplateSelector>
<avalonDock:LayoutRoot>
<avalonDock:LayoutPanel Orientation="Vertical">
<avalonDock:LayoutDocumentPane/>
<avalonDock:LayoutAnchorablePane DockHeight="250">
</avalonDock:LayoutAnchorablePane>
</avalonDock:LayoutPanel>
</avalonDock:LayoutRoot>
</avalonDock:DockingManager>
</Grid>
</Controls:MetroWindow>
MainViewModel.cs
public class MainViewModel : Screen, IMainViewModel
{
IPanelBaseViewModel _activeDocument;
readonly IOutputViewModel _textOutputViewModel;
readonly IModeSelectionViewModel _modeSelectionViewModel;
readonly ILoadViewModel _paLoadViewModel;
readonly IFaultLogViewModel _faultLogViewModel;
readonly IHealthViewModel _paHealthViewModel;
IPanelBaseViewModel _closingDocument;
string name;
public BindableCollection<IPanelBaseViewModel> Tools { get; set; }
public BindableCollection<IPanelBaseViewModel> Documents { get; set; }
public IPanelBaseViewModel ActiveDocument
{
get { return _activeDocument; }
set { _activeDocument = value; NotifyOfPropertyChange(() => ActiveDocument); }
}
public string Name
{
get { return name; }
set { name = value; NotifyOfPropertyChange(() => Name); }
}
public MainViewModel(IOutputViewModel outputViewModel,
IHealthViewModel PAHealthViewModel,
IModeSelectionViewModel ModeSelectionViewModel,
ILoadViewModel PALoadViewModel,
IFaultLogViewModel FaultLogViewModel
)
{
DisplayName = "Debug GUI v" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
_paHealthViewModel = PAHealthViewModel;
_textOutputViewModel = outputViewModel;
_modeSelectionViewModel = ModeSelectionViewModel;
_paLoadViewModel = PALoadViewModel;
_faultLogViewModel = FaultLogViewModel;
Tools = new BindableCollection<IPanelBaseViewModel> { _textOutputViewModel };
Documents = new BindableCollection<IPanelBaseViewModel> { };
MenuItemClick("ModeSelection");
}
public void AddDocument(IPanelBaseViewModel pbvm)
{
if (!Documents.Contains(pbvm))
{
Documents.Add(pbvm);
}
ActiveDocument = pbvm;
}
public void DocumentClosingListener(DocumentClosingEventArgs e)
{
_closingDocument = (IPanelBaseViewModel)e.Document.Content;
}
public void DocumentClosedListener()
{
Documents.Remove(_closingDocument);
}
public void MenuItemClick(string item)
{
switch (item)
{
case "ModeSelection":
AddDocument(_modeSelectionViewModel);
break;
case "Load":
AddDocument(_paLoadViewModel);
break;
case "FaultLog":
AddDocument(_faultLogViewModel);
break;
case "Health":
AddDocument(_paHealthViewModel);
break;
default:
break;
}
_textOutputViewModel.IsActive = true;
}
}
这是因为您的窗口将AllowsTransparency 设置为True。 AvalonDock 不支持此功能。我也在寻找解决方案。