0

In my WPF app, the following XAML in Toolbar is showing ToolTip for Paste button but not for the Copy button. Question: Why it may be happening and how can we resolve it?

<Window x:Class="myWPFApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfMkTxTest"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="1140.038">
    <Grid>
        <!-- Set the styles for the tool bar. -->
        <Grid.Resources>
            <Style TargetType="{x:Type Button}" x:Key="formatTextStyle">
                <Setter Property="FontFamily" Value="Palatino Linotype"></Setter>
                <Setter Property="Width" Value="30"></Setter>
                <Setter Property="FontSize" Value ="14"></Setter>
                <Setter Property="CommandTarget" Value="{Binding ElementName=mainRTB}"></Setter>
            </Style>

            <Style TargetType="{x:Type Button}" x:Key="formatImageStyle">
                <Setter Property="Width" Value="30"></Setter>
                <Setter Property="CommandTarget" Value="{Binding ElementName=mainRTB}"></Setter>
            </Style>

            <Style TargetType="{x:Type RichTextBox}">
                <Setter Property="FontFamily" Value="calibri (body)" />
                <Setter Property="FontSize" Value="11" />
            </Style>

            <Style TargetType="{x:Type Paragraph}">
                <Setter Property="Margin" Value="0" />
            </Style>
        </Grid.Resources>

        <DockPanel Name="mainPanel">

            <!-- This tool bar contains all the editing buttons. -->
            <ToolBar Name="mainToolBar" Height="30" DockPanel.Dock="Top">
....
<Button Style="{StaticResource formatImageStyle}" Command="ApplicationCommands.Copy" ToolTip="Copy">
  <Image Source="Images\editcopy.png"></Image>
</Button>
<Button Style="{StaticResource formatImageStyle}" Command="ApplicationCommands.Paste" ToolTip="Paste">
  <Image Source="Images\editpaste.png"></Image>
</Button>
....

        </DockPanel>
    </Grid>
</Window>
nam
  • 21,967
  • 37
  • 158
  • 332

2 Answers2

1

To show tooltip for command binding buttons, set ToolTipService.ShowOnDisabled = "True"

<DockPanel Name="mainPanel" VerticalAlignment="Top">       
<ToolBar Name="mainToolBar" Height="30" DockPanel.Dock="Top">
    <Button Style="{StaticResource formatImageStyle}" Command="ApplicationCommands.Copy"  ToolTip="Copy" ToolTipService.ShowOnDisabled="True">
        <Image Source="C:\Users\mcpl\Documents\Visual Studio 2015\Projects\TestApplication\TestApplication\Images\Add.png"></Image>
    </Button>
    <Button Style="{StaticResource formatImageStyle}" Command="ApplicationCommands.Paste"  ToolTip="Paste" ToolTipService.ShowOnDisabled="True">
        <Image Source="C:\Users\mcpl\Documents\Visual Studio 2015\Projects\TestApplication\TestApplication\Images\edit.png"></Image>
    </Button>
</ToolBar>

Muthukumar K
  • 311
  • 1
  • 9
  • Although your suggestion works I was curious as to why the `ToolTip` works for `Paste` button without setting `ShowOnDisabled` property to true but it does not work for the `Copy` button? I thought that the above property would be needed if a button is disabled and you still want to show the `ToolTip` as explained [here](https://stackoverflow.com/a/3149135/1232087), as well. My `Copy` button is not disabled as it's copy functionality works fine when I click on it to copy a text. – nam May 08 '19 at 15:31
0

Try using CommandBinding

<ToolBar Name="mainToolBar" Height="30" DockPanel.Dock="Top">
                <Button Style="{StaticResource formatImageStyle}"  ToolTip="Copy">
                    <Button.CommandBindings>
                        <CommandBinding Command="ApplicationCommands.Copy"  />
                    </Button.CommandBindings>
                    <Image Source="C:\Users\heruvath\Desktop\user-48.png"></Image>
                </Button>
                <Button Style="{StaticResource formatImageStyle}"  ToolTip="Paste">
                    <Button.CommandBindings>
                        <CommandBinding Command="ApplicationCommands.Paste"  />
                    </Button.CommandBindings>
                    <Image Source="C:\Users\heruvath\Desktop\user-48.png"></Image>
                </Button>

            </ToolBar>
Justin CI
  • 2,693
  • 1
  • 16
  • 34
  • Thank you for trying to help. Your suggestion did not make any difference at all. I think what you're suggesting is for built-in Edit commands for Copy/Cut/Paste etc so one does NOT need to specifically write a code for them. I'm not sure if it has anything to do with ToolTip. – nam May 08 '19 at 16:27