【问题标题】:Ribbon application menu (dropdown) is not minimizing (closing or losing focus) in WPF application while loading after a click event在单击事件后加载时,功能区应用程序菜单(下拉菜单)未在 WPF 应用程序中最小化(关闭或失去焦点)
【发布时间】:2022-07-20 18:39:01
【问题描述】:

我有一个包含功能区的 wpf 应用程序。功能区有应用程序菜单,它是一个像 image 这样的下拉菜单。此应用程序菜单包含最近文件列表,用于打开类似this 的文件。现在,当用户从列表中选择一个最近的文件时,此下拉菜单会卡住,直到文件加载。如果我在像 this 一样加载文件时并行打开它,则下拉菜单位于任何其他应用程序(如 powerpoint)的顶部。我希望在加载文件时关闭下拉菜单,以便显示一些进度条或加载图标。

xaml 代码如下。

<Ribbon>
        <Ribbon.ApplicationMenu>
            <RibbonApplicationMenu >
                <RibbonApplicationMenu.AuxiliaryPaneContent>
                    <StackPanel>
                        <TextBlock Text="{DynamicResource Recent}" />
                        <Separator />
                        <RibbonGallery
                            CanUserFilter="False"
                            ScrollViewer.VerticalScrollBarVisibility="Auto">
                            <RibbonGalleryCategory Background="Transparent" ItemsSource="{Binding RecentFiles}">
                                <RibbonGalleryCategory.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <StackPanel IsItemsHost="True" Orientation="Vertical" />
                                    </ItemsPanelTemplate>
                                </RibbonGalleryCategory.ItemsPanel>
                                <RibbonGalleryCategory.ItemTemplate>
                                    <DataTemplate>
                                        <Grid>
                                            <Grid.InputBindings>
                                                <MouseBinding
                                                    Command="{Binding DataContext.opencommand, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
                                                    CommandParameter="{Binding FilePath}"
                                                    MouseAction="LeftClick" />
                                            </Grid.InputBindings>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="Auto" />
                                                <ColumnDefinition Width="*" />
                                            </Grid.ColumnDefinitions>

                                            <TextBlock Text="{Binding Numero}" TextDecorations="Underline" />
                                            <TextBlock
                                                Grid.Column="1"
                                                Margin="0,0,10,0"
                                                Text="{Binding FileName}"
                                                TextTrimming="CharacterEllipsis"
                                                ToolTip="{Binding FilePath}" />
                                        </Grid>
                                    </DataTemplate>
                                </RibbonGalleryCategory.ItemTemplate>
                            </RibbonGalleryCategory>
                        </RibbonGallery>
                    </StackPanel>
                </RibbonApplicationMenu.AuxiliaryPaneContent>
            </RibbonApplicationMenu>
        </Ribbon.ApplicationMenu> >
    </Ribbon>

请帮助我任何想法。我尝试用ribbonbutton替换文本块,但点击事件不起作用。任何帮助表示赞赏。

谢谢

【问题讨论】:

    标签: c# wpf xaml drop-down-menu ribbon


    【解决方案1】:

    在加载文件之前将布尔值绑定到 Ribbon.IsDropDownOpen 并将其设置为 false。也许您必须使用 Dispatcher 才能使其工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-22
      • 1970-01-01
      • 2011-11-26
      相关资源
      最近更新 更多