簡體   English   中英

WPF TabItem未突出顯示

[英]WPF TabItem not highlighted it should

我有三個標簽。 只需簡單地單擊它們,它們就會按照需要分別突出顯示。

這些選項卡后面有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>

ViewModel級別的C#代碼(CaptureSetup CaptureSetup()是單擊第一個選項卡的RelyCommand,而HardwareSetupLS()是菜單上彈出窗口的RefereshCaptureSetup() ,而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突出顯示。

我覺得您的問題中缺少一些重要的邏輯(例如,如何更新IsCaptureSetupTabSelectedIsCaptureTabSelected ),但是無論如何,這是查看代碼的三個指針:

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

  • 您似乎正在更新由綁定屬性包裝的內部屬性(例如_isCaptureSetupTabSelected = true而不是IsCaptureSetupTabSelected = true ),因此可能缺少UI期望的正確INotifyPropertyChanged事件。

  • 確保正確的TabItem處於焦點。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM