2014-01-09 17 views
0

我有三個選項卡。通過單獨點擊,他們將單獨突出顯示,因爲他們應該。WPF TabItem沒有突出顯示它應該

這些選項卡後面有RelyCommand。無論何時單擊該線程,程序都應該返回第一個TabItem,並且應該突出顯示。但是,單擊第二個選項卡時,第一個選項卡不會像應該那樣突出顯示,儘管它的行爲類似於單擊。它只是沒有突出顯示。

這裏是在視圖級別後面的兩個選項卡

XAML代碼的代碼:

<StackPanel Orientation="Horizontal" 
         Background="{x:Null}"> 
       <TabControl Height="50" Margin="12,0,0,0"> 
        <TabItem Name="tiCaptureSetup" IsSelected="{Binding Path=IsCaptureSetupTabSelected, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"> 
         <TabItem.Header>        
          <Button Name="btnCaptureSetup" 
            Grid.Column="0" 
            Width="90" 
            Height="40" 
            Margin="5" 
            ToolTip="Capture Setup" 
            Content="Capture Setup" 
            Click="btnCaptureSetup_Click" 
            IsEnabled="{Binding Path=CaptureSetupButtonStatus, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" 
            IsDefault="True" 
            ></Button> 
         </TabItem.Header> 
        </TabItem> 
        <TabItem Name="tiCapture" IsSelected="{Binding Path=IsCaptureTabSelected, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"> 
         <TabItem.Header> 
          <Button Name="btnCapture" 
            Grid.Column="0" 
            Margin="5" 
            Width="90" 
            Height="40" 
            ToolTip="Capture" 
            Content="Capture" 
            Click="btnCapture_Click" 
            IsEnabled="{Binding Path=CaptureButtonStatus, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"></Button> 
         </TabItem.Header> 
        </TabItem> 

在視圖模型級中的C#代碼(CaptureSetup()是RelyCommand爲點擊第一個選項卡,和HardwareSetupLS()是菜單上的彈出窗口的RelyCommand和RefereshCaptureSetup()基本上試圖在彈出菜單窗口時檢索第一個選項卡)

public void CaptureSetup() 
     { 
      Command command = new Command(); 
      command.Message = "Capture Setup"; 
      command.CommandGUID = new Guid("6ecb028e-754e-4b50-b0ef-df8f344b668e"); 

      _eventAggregator.GetEvent<CommandShowDialogEvent>().Publish(command); 
     } 

     public void HardwareSetupLS() 
     { 
      //RefereshCaptureSetup(); // refresh panel when hardware setting window is loaded. 

      Command command = new Command(); 
      command.Message = "HardwareSetupLS"; 
      command.CommandGUID = new Guid("64c695e6-8959-496c-91f7-5a9a95d91e0d"); 

      _eventAggregator.GetEvent<CommandShowDialogEvent>().Publish(command); 
      RefereshCaptureSetup(); 
     } 

     public void RefereshCaptureSetup() // refresh CaptureSetup UI 
     { 
      _isCaptureSetupTabSelected = true; 
      _isCaptureTabSelected = false; 
      _isReviewTabSelected = false; 
      Command command = new Command(); 
      command.Message = "Capture Setup"; 
      command.CommandGUID = new Guid("{6ecb028e-754e-4b50-b0ef-df8f344b668e}"); 

      _eventAggregator.GetEvent<CommandShowDialogEvent>().Publish(command); 
     } 

我很困惑,在這一點上,我還能做些什麼來使第一個TabItem突出顯示,因爲它應該。

回答

1

感覺好像是你的問題丟失(例如,如何IsCaptureSetupTabSelectedIsCaptureTabSelected更新)一些重要的邏輯,但無論如何,這裏是來自看你的代碼三分:

  • UpdateSourceTrigger=PropertyChanged是無用的,因爲你的綁定是OneWay(從ViewModel中的源代碼到您的UI,源代碼永遠不會更新)。如果您已經編寫了一些預期在鼠標點擊時收到IsSelected更改通知的邏輯,則不會發生這種情況。

  • 你似乎更新內的屬性由你的綁定屬性(例如的替代_isCaptureSetupTabSelected = trueIsCaptureSetupTabSelected = true)包裹,因此,可能缺少適當的INotifyPropertyChanged事件的UI期待。

  • 確保正確的TabItem焦點。

+0

是的,工作。我將綁定更改爲TwoWay,並將_isCaptureSetupTabSelected = true更改爲IsCaptureSetupTabSelected = true。非常感謝! –