Hide or disable input gesture text in wpf

Suppose we use the gesture "Ctrl + S" to save the project.

In the menu "File" - "Save Ctrl + S" such text is displayed. Now about the canececute SaveCommand, I check if the project is required to be saved or not. If this is not required, then "Save" is disabled.

In this case, I see a menu item, for example, "Ctrl + S". I also have to hide this input gesture text.

Ideas?

Any new channel

This question has not received love: (...

+3
source share
1 answer

, . , , , , .

, , .

<ControlTemplate x:Key="{x:Static MenuItem.SubmenuItemTemplateKey}"
                 TargetType="{x:Type MenuItem}">
    <Border x:Name="Border"
            TextElement.Foreground="{DynamicResource SubMenuItemTextForegroundColor}"
            Background="{DynamicResource FileMenuBackgroundBrush}">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"
                                  SharedSizeGroup="Icon" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto"
                                  SharedSizeGroup="Shortcut" />
                <ColumnDefinition Width="13" />
            </Grid.ColumnDefinitions>
            <ContentPresenter x:Name="Icon"
                              Margin="6,0,6,0"
                              VerticalAlignment="Center"
                              ContentSource="Icon" />
            <Border x:Name="Check"
                    Width="13"
                    Height="13"
                    Visibility="Collapsed"
                    Margin="6,0,6,0"
                    Background="#C0C0C0"
                    BorderThickness="1"
                    BorderBrush="#404040">
                <Path x:Name="CheckMark"
                      Width="7"
                      Height="7"
                      Visibility="Hidden"
                      SnapsToDevicePixels="False"
                      Stroke="#404040"
                      StrokeThickness="2"
                      Data="M 0 0 L 7 7 M 0 7 L 7 0" />
            </Border>
            <ContentPresenter x:Name="HeaderHost"
                              Grid.Column="1"
                              ContentSource="Header"
                              RecognizesAccessKey="{TemplateBinding Tag,
                                                                    Converter={StaticResource TagToRecognizesAccessKeyConverter} 
                                                   }"
                              VerticalAlignment="Center" />
            <TextBlock x:Name="InputGestureText"
                       Grid.Column="2"
                       Text="{TemplateBinding InputGestureText}"
                       Margin="5,2,0,2"
                       DockPanel.Dock="Right" />
        </Grid>
    </Border>
    <ControlTemplate.Triggers>
        <Trigger Property="Icon"
                 Value="{x:Null}">
            <Setter TargetName="Icon"
                    Property="Visibility"
                    Value="Hidden" />
        </Trigger>
        <Trigger Property="IsChecked"
                 Value="true">
            <Setter TargetName="CheckMark"
                    Property="Visibility"
                    Value="Visible" />
        </Trigger>
        <Trigger Property="IsCheckable"
                 Value="true">
            <Setter TargetName="Check"
                    Property="Visibility"
                    Value="Visible" />
            <Setter TargetName="Icon"
                    Property="Visibility"
                    Value="Hidden" />
        </Trigger>
        <Trigger Property="IsHighlighted"
                 Value="true">
            <Setter Property="Background"
                    TargetName="Border"
                    Value="{DynamicResource SubMenuItemMouseOverBackgroundBrush}" />
            <Setter Property="TextElement.Foreground"
                    TargetName="Border"
                    Value="{DynamicResource FileMenuBackgroundBrush}" />
        </Trigger>
        <Trigger Property="IsEnabled"
                 Value="false">
            <Setter TargetName="HeaderHost"
                    Property="TextElement.Foreground"
                    Value="#DDDDDD" />
            <Setter TargetName="InputGestureText"
                    Property="TextElement.Foreground"
                    Value="#DDDDDD" />
        </Trigger>
    </ControlTemplate.Triggers>
</ControlTemplate>
+2

Source: https://habr.com/ru/post/1762606/


All Articles