1

我有几个应该RibbonTab根据Content.TabControl

问题是有时它不起作用,我的远程 Windows XP 上的错误似乎比我使用 Windows 7 的主计算机更频繁(可能是因为它更慢)。发生错误时,再次切换选项卡无济于事,并且对于共享相同的任何视图都不起作用IValueConverter

<ribbon:RibbonWindow Title="{Binding DisplayName}"
    x:Name="RibbonWindow"
    x:Class="Abc.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ribbon="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
    xmlns:c="clr-namespace:Abc.Converters">
<ribbon:RibbonWindow.Resources>
    <c:FoobarConverter x:Key="Foobar" />
    <c:FooConverter x:Key="Foo" />
    <c:BarConverter x:Key="Bar" />
</ribbon:RibbonWindow.Resources>
<DockPanel>
    <ribbon:Ribbon DockPanel.Dock="Top">
        <a:FoobarRibbonTab IsSelected="{Binding SelectedTab, Mode=OneWay, Converter={StaticResource Foobar}}" />
        <a:FooRibbonTab IsSelected="{Binding SelectedTab, Mode=OneWay, Converter={StaticResource Foo}}" />
        <a:BarRibbonTab IsSelected="{Binding SelectedTab, Mode=OneWay, Converter={StaticResource Bar}}" />
    </ribbon:Ribbon>
    <TabControl ItemsSource="{Binding Tabs}"
                SelectedItem="{Binding SelectedTab}"/>
</DockPanel>

public class FooConverter : IValueConverter
{
    public List<Type> ValidTypes = new List<Type>();

    public FooConverter()
    {
        ValidTypes = new List<Type>
        {
            typeof(FooView),
            // etc...
        };
    }

    public virtual object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        var tabItemBase = value as TabItemBase;

        return tabItemBase != null && tabItemBase.Content != null && ValidTypes.Contains(tabItemBase.Content.GetType());
    }

    public virtual object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

更新

每个RibbonTab都有自己的Converter,每个View只存在于一个Converter。当我使用Ctrl + Tab时,错误发生得更早。

4

0 回答 0