我想删除它们,因为这会给我带来很多问题。如果有办法解决它,我会很乐意尝试。 使用它的前几分钟我得到了3个不同的例外,我无法弄清楚如何删除那些该死的选项。
固定和取消固定以及固定会抛出InvalidOperationException,因为操作由于对象的当前状态而无效。
有时固定和取消固定将打开一个对话框并询问我一个文件,我不希望发生这种情况,但它正在发生并且它会引发异常。
我不小心点击了关闭按钮,我无法恢复窗口。 真的很令人沮丧。我相信其他avalondock用户已经遇到过这种情况。
因为我不想浪费太多时间,所以我会在这里问。 你是如何解决这些例外或删除这些按钮的?感谢。
答案 0 :(得分:3)
我和你的问题完全一样。我不想从实际用户界面中删除图标,我只是使用事件处理程序禁用它们
以下是我的工作方式:
删除隐藏和自动隐藏命令:
我添加了以下处理程序:
CommandManager.AddPreviewExecutedHandler(this, new ExecutedRoutedEventHandler(this.ContentClosing))
这就是ContentClosing
的样子:
/// <summary>
/// Handler called when user clicked on one of the three buttons in a DockablePane
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ContentClosing(object sender, ExecutedRoutedEventArgs e)
{
if (e.Command == ApplicationCommands.Close || e.Command == DockablePaneCommands.Close)
{
e.Handled = true;
DockManager source = sender as DockManager;
if (source.ActiveContent != null)
{
source.ActiveContent.Close();
}
}
else if (e.Command == DockablePaneCommands.Hide || e.Command == DockablePaneCommands.ToggleAutoHide)
{
e.Handled = true;
} }
此处理程序实际上是关闭正确的内容。出于某种原因,有时AvalonDock
将关闭另一个内容,因为它具有焦点(点击十字架不会将焦点放在您的内容上,因此它将关闭当前关注的内容......)
如您所见,我只是覆盖事件并手动关闭我的组件
不幸的是,这并未涵盖所有情况。我也出于某种原因(hello buggy AvalonDock)实际捕获关闭按钮上的点击,因为有一个边缘情况:如果删除最后一个组件,您将无法添加新组件,因为{{1将删除最后剩余的面板。此外,如果您关闭其中包含许多标签的AvalonDock
,DockableContent
将关闭所有标签,因此我必须实施某些内容才能关闭当前标签(这更有意义)我不得不为添加的每个内容添加一个鼠标按下处理程序以捕获此事件。通过以下技巧,我可以做一个解决方法来避免这个错误:
AvalonDock
同样,对于这些小问题来说,这是一项令人难以置信的重大工作,但不幸的是,这 /// <summary>
/// Handler called when a DockableContent state changed.
/// We need it to define a PreviewMouseDownHandler for each DockablePane
/// possibly created (which are usually created upon docking a floating window
/// to a new position) in order to handle single DockableContent closing
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void NewContent_StateChanged(object sender, RoutedEventArgs e)
{
DockableContent source = sender as DockableContent;
if (source.State == DockableContentState.Docked && source.Parent is DockablePane)
{
DockablePane parent = source.Parent as DockablePane;
parent.PreviewMouseDown -= mouseHandler;
parent.PreviewMouseDown += mouseHandler;
}
}
/// <summary>
/// Handler called on mouse down on a DockablePane.
/// It is designed to detect where did the user click, and
/// if he clicked on Close, only the current DockableContent will be closed
/// (unlike the native behavior which requires us to close the entire DockablePane
/// upon clicking on Close...)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void DockablePaneMouseDown(object sender, MouseButtonEventArgs e)
{
DockablePane source = sender as DockablePane;
if (e.OriginalSource is AvalonDock.ImageEx)
{
//User clicked on one of the three icons on the top-right corner of the DockablePane
if ((e.OriginalSource as AvalonDock.ImageEx).Source.ToString().Contains("PinClose"))
{
RemoveFromUI(source.SelectedItem as DockableContent);
e.Handled = true;
}
}
}
/// <summary>
/// Removes a DockableContent from the currently displayed UI
/// (called when the original DockableItemsSource changed)
/// </summary>
/// <param name="content">The content to be removed</param>
private void RemoveFromUI(DockableContent content)
{
if (content == null)
{
return;
}
DockablePane parent = content.Parent as DockablePane;
if (this.ActiveContent == parent.SelectedItem)
{
this.ActiveContent = null;
}
(parent.SelectedItem as DockableContent).Close();
//// If the current DockablePane is left empty, we ensure to close it
if (parent.Items.Count == 0)
{
//This case is needed if we are trying to remove the last DockablePane from a DockingManager
//Native behavior will NOT set the Content property if you remove the last DockablePane:
//it will therefore consider this CLOSED DockablePane as the current ActiveContent,
//and will try to add new contents in this closed pane, which seems rather disturbing.
//Here we explicitly set the Content property to null if we are removing the last element,
//so next time user adds a tab, it will be added as the new Content!
if (parent == this.Content)
{
this.Content = null;
}
parent.Close();
parent.Visibility = Visibility.Hidden;
}
}
远非生产环境准备就绪,我不得不调整这些东西以使其发挥作用。
希望它对你也有用,并为自己省去一些我已经给这个问题带来的麻烦!
答案 1 :(得分:3)
如果您使用MVVM方法进行Avalon Dock(版本2),那么您可以将它放在视图模型中:
DockAsDocumentCommand = new DelegateCommand(() => { }, () => false);
AutoHideCommand = new DelegateCommand(() => { }, () => false);
CanClose = false;
CanHide = false;
那些都需要对它们进行TwoWay绑定和NotifyPropertyChanged。
执行此操作后,关闭,隐藏和移动到其他文档的所有选项都将被删除或显示为灰色。
答案 2 :(得分:1)
如果使用MVVM,在XAML中将CanClose设置为false就足够了,如下所示:
<avalondock:DockingManager.LayoutItemContainerStyleSelector>
<avalon:PanesStyleSelector>
<avalon:PanesStyleSelector.DeviceStyle>
<Style TargetType="{x:Type avalondock:LayoutItem}">
<Setter Property="Title" Value="{Binding Model.Name}"/>
<Setter Property="ToolTip" Value="{Binding Model.Name}"/>
<Setter Property="ContentId" Value="{Binding Model.Id}"/>
<Setter Property="CanClose" Value="False"></Setter>
</Style>
</avalon:PanesStyleSelector.DeviceStyle>
</avalon:PanesStyleSelector>
</avalondock:DockingManager.LayoutItemContainerStyleSelector>
答案 3 :(得分:0)
摆脱Close
,CloseAll
和CloseAllButThis
命令的另一种方法是在LayoutItemContainerStyleSelector
中将命令设置为null。类似的东西:
<xcad:DockingManager.LayoutItemContainerStyleSelector>
<local:PanesStyleSelector>
<local:PanesStyleSelector.DocStyle>
<Setter Property="CloseCommand" Value="{Binding Model.CloseCommand}"/>
<Setter Property="CloseAllCommand" Value="{x:Null}" />
<Setter Property="CloseAllButThisCommand" Value="{x:Null}" />
</Style>
</local:PanesStyleSelector.DrawingStyle>
</local:PanesStyleSelector>
</xcad:DockingManager.LayoutItemContainerStyleSelector>
PanesStyleSelector
是一个简单的StyleSelector
(我有多种样式可供选择,具体取决于窗格类型,所以我需要一个StyleSelector
;如果你只有Public Class PanesStyleSelector
Inherits StyleSelector
Public Property DocStyle() As Style
Public Overrides Function SelectStyle(item As Object, container As System.Windows.DependencyObject) As System.Windows.Style
Return DocStyle
End Function
End Class
,你可能想跳过它一种类型的窗格。以下是简化版本。):
CloseAll
这将禁用文档选项卡上下文菜单中的CloseAllButThis
和CloseCommand
命令。另请注意,我在VM中处理 var execSync = require('sync-exec');
var npmGlobalPath = execSync('npm config get prefix');
console.log(npmGlobalPath);
,我可以决定是关闭文档还是提示用户。这将消除意外点击关闭按钮。