WPF and MVVMLight - Open tooltip of a button when another button is clicked

316 views Asked by At

I want to open tooltip of a button when another button is clicked but the tooltip is opening on the left top of the window. When i move my mouse over the first button, it works right and tooltip is shown near the first button but when i clicked the second button, tooltip is shown on the left top of the window instead of being shown near the first button. How can i place the tooltip near the first button as it should be?

Thanks in advance.

Here is the xaml part:

    <s:SurfaceToggleButton x:Name="XMenu" IsChecked="{Binding XMenuIsChecked}">
        <s:SurfaceToggleButton.ToolTip>
            <ToolTip IsOpen="{Binding IsTooltipOpen}" DataContext="{Binding Path=PlacementTarget.DataContext, RelativeSource={x:Static RelativeSource.Self}}">
                <TextBlock Text="{x:Static p:Language.Label_Tooltip_XMenu}"/>
             </ToolTip>
         </s:SurfaceToggleButton.ToolTip>
         <i:Interaction.Triggers>
             <i:EventTrigger EventName="Click">
                 <Custom:EventToCommand Command="{Binding XMenuOpen}" PassEventArgsToCommand="True" />
             </i:EventTrigger>
         </i:Interaction.Triggers>
    </s:SurfaceToggleButton>
    <s:SurfaceButton>
         <i:Interaction.Triggers>
            <i:EventTrigger EventName="Click">
                <Custom:EventToCommand Command="{Binding OpenTooltips}" PassEventArgsToCommand="True" />
            </i:EventTrigger>
         </i:Interaction.Triggers>
    </s:SurfaceButton>

Here is the code in view model class, MVVM part:

private RelayCommand _OpenTooltips;

public RelayCommand OpenTooltips
{
    get
    {
       return _OpenTooltips
           ?? (_OpenTooltips = new RelayCommand(
           () =>
           {
              IsTooltipOpen = true;
           }));
    }
}

where Custom is defined as mvvmlight

xmlns:Custom="http://www.galasoft.ch/mvvmlight" 

and the tooltip style is defined as:

   <Style TargetType="ToolTip">
        <Setter Property = "HorizontalOffset" Value="0"/>
        <Setter Property = "VerticalOffset" Value="10"/>
        <Setter Property = "Placement" Value="Right"/>
        <Setter Property = "HasDropShadow" Value="false"/>
    </Style>
0

There are 0 answers