2013-03-19 36 views
0

RibbonTab IsSelected not working這是一個最小化的誤差再現。WPF IsSelected爲RibbonTab結合停止工作時CTRL + TAB

這裏是演示應用程序的主窗口:

enter image description here

當我們點擊應用程序菜單(藍色箭頭),彈出一個菜單了。

enter image description here

如果我們點擊主視圖,標籤項添加到一個tabpanel。

enter image description here

「主視圖」是標籤的包頭和標籤項目的內容,沒什麼可奇怪的。

如果我們還額外的點擊來看,我們拿到的這款:

enter image description here

我們可以看到,一個標籤已經顯形和額外的東西顯示色帶。如果我們在兩個Tabpanel選項卡之間切換,則額外的RibbonTab僅在選擇「額外視圖」時纔可見。

現在,如果我們選擇「額外視圖」選項卡,以便額外的RibbonTab可見並單擊該文本框,以便我們在其中閃爍光標並按Ctrl + Tab幾次以Tab鍵順序導航元素,我們很快就會再次選中標題爲「額外視圖」的標籤。額外的RibbonTab將看起來與我們所期望的不同。

enter image description here

所剩下的唯一的事情是標籤文本「額外的標籤」,文本框是不存在任何更長的時間。爲什麼不?

如果我們單擊tabpanel中的選項卡(顯示「主視圖」和「額外視圖」,「額外選項卡」僅在選擇「額外視圖」時纔可見,這是預期的行爲。功能區標籤分隔符不再有任何意想不到的

RibbonTab的可見性綁定到TabPanel中選定TabItem的類型,使用轉換器返回Visibility.Visible,如果該選項卡項目類型爲ExtraView但如果類型是其他內容(如MainView)

RibbonTab的IsSelected屬性也綁定到選定的tabitem,使用轉換器,如果選項卡項類型爲ExtraView。

這是提到一個程序,菜單選項卡將不僅僅是「額外選項卡」更是這樣重要的是,它會成爲選擇時tabpanels內容的類型是正確的小例子。我這樣說要強調IsSelected是需要的(除了可見性)。

任何幫助,非常感謝。

MainWindow.xaml:

<RibbonWindow x:Class="TestProblematicRibbons.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:test="clr-namespace:TestProblematicRibbons" 
    xmlns:Converters="clr-namespace:TestProblematicRibbons.Converters" 
    Height="300" Width="350"> 
    <RibbonWindow.DataContext> 
    <test:MainWindowViewModel/> 
    </RibbonWindow.DataContext> 
    <RibbonWindow.Resources> 
    <Converters:ExtraRibbonTabBooleanConverter x:Key="ExtraRibbonTabBoolean" /> 
    <Converters:ExtraRibbonTabVisibilityConverter x:Key="ExtraRibbonTabVisibility" /> 
    </RibbonWindow.Resources> 
    <DockPanel> 
    <Ribbon DockPanel.Dock="Top"> 
     <Ribbon.ApplicationMenu> 
     <RibbonApplicationMenu> 
      <RibbonApplicationMenuItem Header="main view" 
      Command="{Binding CreateMainViewCommand}"/> 
      <RibbonApplicationMenuItem Header="extra view" 
      Command="{Binding CreateExtraViewCommand}"/> 
     </RibbonApplicationMenu> 
     </Ribbon.ApplicationMenu> 

     <RibbonTab Header="extra tab" 
      IsSelected="{Binding SelectedTab, Mode=OneWay, Converter={StaticResource ExtraRibbonTabBoolean}}" 
      Visibility="{Binding SelectedTab, Mode=OneWay, Converter={StaticResource ExtraRibbonTabVisibility}}"> 
     <RibbonGroup> 
      <RibbonTextBox /> 
     </RibbonGroup> 
     </RibbonTab> 
    </Ribbon> 
    <TabControl 
     ItemsSource="{Binding Tabs}" SelectedItem="{Binding SelectedTab}" /> 
    </DockPanel> 
</RibbonWindow> 

MainWindowModel。CS:

using System.Collections.ObjectModel; 
using System.Windows.Controls; 
using System.Windows.Input; 
using ReactiveUI; 

namespace TestProblematicRibbons 
{ 
    public class MainWindowViewModel: ReactiveObject 
    { 
    private ObservableCollection<TabItem> _tabs 
     = new ObservableCollection<TabItem>(); 

    public ObservableCollection<TabItem> Tabs 
    { 
     get { return _tabs; } 
    } 

    private TabItem _SelectedTab; 
    public TabItem SelectedTab 
    { 
     get { return _SelectedTab; } 
     set { this.RaiseAndSetIfChanged(x => x.SelectedTab, value); } 
    } 

    public ICommand CreateMainViewCommand 
    { get { return new ActionCommand(CreateMainView); } } 

    public ICommand CreateExtraViewCommand 
    { get { return new ActionCommand(CreateExtraView); } } 

    private void CreateMainView() 
    { 
     var view = new MainView(); 
     AddTab(view, "main view"); 
    } 

    private void CreateExtraView() 
    { 
     var view = new ExtraView(); 
     AddTab(view, "extra view"); 
    } 

    private void AddTab(UserControl view, string header) 
    { 
     var tab = new TabItem(); 
     tab.Header = header; 
     tab.Content = view; 
     _tabs.Add(tab); 

     SelectedTab = tab; 
    } 
    } 
} 

ExtraRibbonTabBooleanConverter:

using System; 
using System.Globalization; 
using System.Windows.Controls; 
using System.Windows.Data; 

namespace TestProblematicRibbons.Converters 
{ 
    public class ExtraRibbonTabBooleanConverter: IValueConverter 
    { 
    public object Convert 
     (object value, Type targetType, object parameter, CultureInfo culture) 
    { 
     var item = value as TabItem; 

     return item != null && item.Content is ExtraView; 
    } 

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

ExtraRibbonTabVisibilityConverter:

using System; 
using System.Globalization; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Data; 

namespace TestProblematicRibbons.Converters 
{ 
    public class ExtraRibbonTabVisibilityConverter: IValueConverter 
    { 
    public object Convert 
     (object value, Type targetType, object parameter, CultureInfo culture) 
    { 
     var item = value as TabItem; 

     return item != null && item.Content is ExtraView 
     ? Visibility.Visible 
     : Visibility.Collapsed; 
    } 

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

的MainView和ExtraView只有兩個用戶控件:■與他們的標籤,顯示 「主視圖」 和「額外的觀點「,因此在這裏粘貼代碼的意義不大。

+1

我迷失在細節之中,所以SO必須得到「太多細節」的投票權 – TalentTuner 2013-03-19 10:46:32

+0

請告訴我你在哪裏丟失 – 2013-03-19 10:47:46

回答

0

我通過在某些情況下手動實現綁定來解決了我的問題。似乎不可能完全依賴組合中的綁定。他們顯然可以打擾對方!