gpt4 book ai didi

c# - 阿瓦隆码头 : how to align the tabs to the top right?

转载 作者:太空宇宙 更新时间:2023-11-03 15:20:50 24 4
gpt4 key购买 nike

我正在我的 xaml 文件中创建一个带有 avalonDock 的 DockingManager,但我想不出一种方法来对齐它在右上角创建的选项卡。它们始终位于左上角。

像这样:

enter image description here

我看过:How to set AvalonDock DockablePane to right in WPF但我在“DockingManager”下找不到“ResizingPanel”

有人知道怎么做吗?

这是我的 xaml 示例:

<Grid>
<avalonDock:DockingManager x:Name="dockingManager" Margin="0,10,0,-10"
DocumentsSource="{Binding Files}"
Grid.Row="0" >
<avalonDock:DockingManager.LayoutItemTemplateSelector>
<panel:PanelTemplateSelector>
<panel:PanelTemplateSelector.FileViewTemplate>
<DataTemplate>
<view:Shooting/>
</DataTemplate>
</panel:PanelTemplateSelector.FileViewTemplate>
</panel:PanelTemplateSelector>
</avalonDock:DockingManager.LayoutItemTemplateSelector>


<avalonDock:DockingManager.LayoutItemContainerStyleSelector>
<panel:PanelStyleSelector>
<panel:PanelStyleSelector.StartPageStyle>
<Style TargetType="{x:Type avalonControl:LayoutItem}">
<Setter Property="Title" Value="{Binding Model.Title}"/>
<Setter Property="ToolTip" Value="{Binding Model.StartPageTip}"/>
<Setter Property="CloseCommand" Value="{Binding Model.CloseCommand}"/>
<Setter Property="IconSource" Value="{Binding Model.IconSource}"/>
<Setter Property="ContentId" Value="{Binding Model.ContentId}"/>
<Setter Property="CanClose" Value="False"></Setter>
</Style>
</panel:PanelStyleSelector.StartPageStyle>
</panel:PanelStyleSelector>
</avalonDock:DockingManager.LayoutItemContainerStyleSelector>

<avalonDock:DockingManager.LayoutUpdateStrategy>
<panel:LayoutInitializer/>
</avalonDock:DockingManager.LayoutUpdateStrategy>

</avalonDock:DockingManager>

最佳答案

TabItems 托管在 DocumentPaneTabPanel 中,其 FlowDirection 属性已在构造函数中设置为 LeftToRight,

我建议执行以下操作:

  1. 将以下内容复制到DockingManager所在的窗体中:

    private void DockingManager_LayoutUpdated(object sender, EventArgs e)
    {
    var q = FindVisualChild<Xceed.Wpf.AvalonDock.Controls.DocumentPaneTabPanel>(dockingManager);
    if (q != null)
    {
    q.FlowDirection = FlowDirection.RightToLeft;
    dockingManager.LayoutUpdated -= DockingManager_LayoutUpdated;
    }
    }
    public T FindVisualChild<T>(DependencyObject obj) where T : DependencyObject
    {
    for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
    {
    DependencyObject child = VisualTreeHelper.GetChild(obj, i);
    if (child != null && child is T)
    return (T)child;
    else
    {
    T childOfChild = FindVisualChild<T>(child);
    if (childOfChild != null)
    return childOfChild;
    }
    }
    return null;
    }
  2. 在 InitializeComponent 之后在窗体的构造函数中复制以下内容:

      dockingManager.LayoutUpdated += DockingManager_LayoutUpdated;

现在,我的代码隐藏看起来像这样:

    public MainWindow()
{
InitializeComponent();
dockingManager.LayoutUpdated += DockingManager_LayoutUpdated;
}
private void DockingManager_LayoutUpdated(object sender, EventArgs e)
{
var q = FindVisualChild<Xceed.Wpf.AvalonDock.Controls.DocumentPaneTabPanel>(dockingManager);
if (q != null)
{
q.FlowDirection = FlowDirection.RightToLeft;
dockingManager.LayoutUpdated -= DockingManager_LayoutUpdated;
}
}
public T FindVisualChild<T>(DependencyObject obj) where T : DependencyObject
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(obj, i);
if (child != null && child is T)
return (T)child;
else
{
T childOfChild = FindVisualChild<T>(child);
if (childOfChild != null)
return childOfChild;
}
}
return null;
}

关于c# - 阿瓦隆码头 : how to align the tabs to the top right?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37433313/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com