wpf - Fluent Ribbon SelectedTabItem 或 SelectedTabIndex

标签 wpf mvvm ribbon fluent fluent-ribbon

我在 MVVM 设计模式中使用 Fluent Ribbon 和 View/ViewModel。我的目标是根据选择的选项卡来更改正文。我可以使用 SelectedTabItem 或 SelectedTabIndex 并查找相应的 View 。但是,当选项卡选择更改时,两者都不会触发。在 View 中我有...

<Fluent:Ribbon Grid.Row="0" SelectedTabItem="{Binding SelectedRibbonTab}" SelectedTabIndex="{Binding SelectedRibbonTabIndex}">
</Fluent:Ribbon>
<ContentControl Grid.Row="1" Content="{Binding RibbonTabContent}"/>

在 ViewModel 中我有...

    // Used both Item and Index for troubleshoothing, but need only one or the other for implementation

    private IDictionary<string, FrameworkElement> RibbonTabViews;
    private List<FrameworkElement> RibbonTabViewsList;

    public RibbonTabItem SelectedRibbonTab
    {
        get 
        { 
            return selectedRibbonTab;
        }
        set
        {
            Update(() => SelectedRibbonTab, ref selectedRibbonTab, value, false);
            UpdateContentControl();
        }
    }

    public int SelectedRibbonTabIndex
    {
        get
        {
            return selectedRibbonTabIndex;
        }
        set
        {
            Update(() => SelectedRibbonTabIndex, ref selectedRibbonTabIndex, value, false);
            UpdateContentControl(value);
        }
    }

    public FrameworkElement RibbonTabContent
    {
       get { return ribbonTabContent; }
       set { Update(() => RibbonTabContent, ref ribbonTabContent, value, false); }
    }

    protected void UpdateContentControl()
    {
        RibbonTabContent = RibbonTabViews[SelectedRibbonTab.Header.ToString()];
    }

    protected void UpdateContentControl(int index)
    {
        RibbonTabContent = RibbonTabViewsList[index];
    }

我知道我不需要这两个绑定(bind),但为了排除故障,我同时拥有 Item 和 Index。我认为在 ViewModel 中,每次选项卡更改时都会调用 SelectedRibbonTab 和 SelectedRibbonTabIndex 。不幸的是,情况似乎并非如此。我在每个 setter 和 getter 处都有断点,并且在更改选项卡时都不会被击中。我缺少什么?我多年来一直在 Microsoft Ribbon 中使用这种方法,但由于某种原因,这些方法在 Fluent Ribbon 中不起作用。任何帮助都会很棒,谢谢。

最佳答案

您必须将绑定(bind)模式设置为 TwoWay 才能在 ViewModel 中获取更新的值。

关于wpf - Fluent Ribbon SelectedTabItem 或 SelectedTabIndex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59834382/

相关文章:

c# - 为大尺寸和正常尺寸的 xml 功能区按钮添加两个图像

c# - 将多个ViewModel用于RibbonWindow(带有或不带有Caliburn Micro)

c# - 将数据从子项聚合到父项以进行绑定(bind)

c# - 如何使功能区控件看起来与 Windows 10 文件资源管理器相同?

wpf - 如何保留 TabControl 中选项卡项内的控件状态

c# - 如何在 UserControl 中使用 ContentPresenter

c# - RenderTargetBitmap 呈现错误大小的图像

c# - WPF 基于样式

c# - ViewModel 和 Command 之间的通信

android - 由 : org. koin.core.error.InstanceCreationException : Could not create instance for [type:Factory, primary_type 引起