Sybren
Sybren

Reputation: 1079

MenuItem not showing ToolTip

I have created a style for my custom Control (ButtonAnalysisControl). Everything is working except the ToolTip. When I move the mouse over a MenuItem the ToolTip doesn't show up. I inspected the MenuItems with Snoopand the ToolTip value is correctly set. How can I make the ToolTip work? Bonus question: How can I remove the Border in my ContextMenu?

ContextMenu:

ContextMenu

Generic.xaml Style

<Style TargetType="anal:ButtonAnalysisControl">

    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="anal:ButtonAnalysisControl">

                <ControlTemplate.Triggers>
                    <EventTrigger RoutedEvent="Click">
                        <BeginStoryboard>
                            <Storyboard>
                                <BooleanAnimationUsingKeyFrames Storyboard.TargetName="ContextMenu" Storyboard.TargetProperty="(ContextMenu.IsOpen)">
                                    <DiscreteBooleanKeyFrame KeyTime="00:00:00" Value="True"/>
                                </BooleanAnimationUsingKeyFrames>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                </ControlTemplate.Triggers>

                <ControlTemplate.Resources>
                    <anal:CustomMultiValueConvertor x:Key="CustomMultiValueConvertor"/>
                    <anal:IntToPercentageBrushConvertor x:Key="IntToPercentageBrushConvertor"/>
                </ControlTemplate.Resources>

                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>

                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>

                    <Grid.ContextMenu>
                        <ContextMenu Name="ContextMenu" IsOpen="False" Placement="Top" PlacementTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}">
                            <ContextMenu.ItemsSource>
                                <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="ChildCommands"/>
                            </ContextMenu.ItemsSource>
                            <ContextMenu.ItemContainerStyle>
                                <Style TargetType="{x:Type MenuItem}">
                                    <Setter Property="MenuItem.Header">
                                        <Setter.Value>
                                            <MultiBinding Converter="{StaticResource CustomMultiValueConvertor}">
                                                <Binding Path="Percentage" />
                                                <Binding Path="ViewCommand.Command.Text" />
                                            </MultiBinding>
                                        </Setter.Value>
                                    </Setter>
                                    <Setter Property="MenuItem.IsEnabled" Value="False"/>
                                    <Setter Property="MenuItem.Background" Value="{Binding Percentage, Converter={StaticResource IntToPercentageBrushConvertor}}"/>
                                    <Setter Property="MenuItem.Padding" Value="0"/>
                                    <Setter Property="MenuItem.BorderThickness" Value="0"/>    
                                    <Setter Property="MenuItem.ToolTip" Value="123"/>                                        
                                </Style>
                            </ContextMenu.ItemContainerStyle>
                            <ContextMenu.ItemsPanel>
                                <ItemsPanelTemplate>
                                    <VirtualizingStackPanel Orientation="Vertical"/>
                                </ItemsPanelTemplate>
                            </ContextMenu.ItemsPanel>
                        </ContextMenu>
                    </Grid.ContextMenu>

                    <TextBlock TextAlignment="Center"
                               VerticalAlignment="Stretch" 
                               Foreground="{StaticResource CommandBarForeground}" 
                               Background="{StaticResource MainForegroundBrush}"
                               FontFamily="{StaticResource FontFamily}"
                               FontSize="10"
                               Grid.Column="0" 
                               Grid.Row="0">
                        <TextBlock.Text>
                            <Binding Path="Text" StringFormat="{}{0}%" RelativeSource="{RelativeSource TemplatedParent}" />
                        </TextBlock.Text>                            
                    </TextBlock>
                    <Rectangle Grid.Column="0" 
                               Grid.Row="1">
                        <Rectangle.Fill>
                            <Binding Path="BackgroundBrush" RelativeSource="{RelativeSource TemplatedParent}" />
                        </Rectangle.Fill>
                    </Rectangle>                        
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>

</Style>

Upvotes: 2

Views: 1389

Answers (1)

Sybren
Sybren

Reputation: 1079

I found the answer: the ToolTip didn't show up because the MenuItem is disabled.

Adding this line to my MenuItem style fixed it:

<Setter Property="ToolTipService.ShowOnDisabled" Value="True" />

Upvotes: 4

Related Questions