gpt4 book ai didi

c# - 功能区 ApplicationMenu AuxilaryPane Size

转载 作者:行者123 更新时间:2023-12-03 21:05:15 28 4
gpt4 key购买 nike

如何更改 WPF 功能区 ApplicationMenu 中 AuxilaryPane 的大小?我已将最近的文件列表添加到该区域,但它被截断了。理想情况下,我希望辅助 Pane 像 Word/Excel 一样填满屏幕。

我的代码:

<r:Ribbon.ApplicationMenu>
<r:RibbonApplicationMenu>
<r:RibbonApplicationMenu.AuxiliaryPaneContent>
<StackPanel>
<TextBlock Text="Recent Files" />
<Separator />
<ItemsControl ItemsSource="{Binding RecentFiles}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<r:RibbonApplicationMenuItem Header="{Binding ShortPath}"
Command="{Binding DataContext.OpenRecentFileCommand, RelativeSource={RelativeSource AncestorType=ItemsControl}}"
CommandParameter="{Binding LongPath}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</r:RibbonApplicationMenu.AuxiliaryPaneContent>
</r:RibbonApplicationMenu>
</r:Ribbon.ApplicationMenu>

最佳答案

根据此线程中的答案,我发现最简单的方法是将 RibbonApplicationMenu 子类化并将第三列的宽度设置为自动。

 public class CustomRibbonApplicationMenu : System.Windows.Controls.Ribbon.RibbonApplicationMenu
{
public override void OnApplyTemplate()
{
base.OnApplyTemplate();

System.Windows.DependencyObject obj = this.GetTemplateChild("PART_AuxiliaryPaneContentPresenter");

System.Windows.Controls.ContentPresenter c = obj as System.Windows.Controls.ContentPresenter;

((System.Windows.Controls.Grid)((System.Windows.Controls.Border)c.Parent).Parent).ColumnDefinitions[2].Width = System.Windows.GridLength.Auto;
}
}

现在你只需要改变你的Ribbon xaml

<Ribbon.ApplicationMenu>
<RibbonApplicationMenu>

<Ribbon.ApplicationMenu>
<ctrl:CustomRibbonApplicationMenu>

关于c# - 功能区 ApplicationMenu AuxilaryPane Size,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6766168/

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