根据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
时,错误会更早发生。