WPF Tooltip with controls

I have a project in which I would like to have a tooltip over some control that will contain some controls, such as textbox and datepicker. The idea would be to have some kind of pop-up window with limited graphics, but some control wo interact.

I know how to add a “normal” tooltip to a control, but when you move, the tooltip disappears, so I can’t interact with it.

Is it possible? If so, how and if not, is there an alternative to this?

thank

+5
source share
1 answer

You should use PopupinsteadToolTip

. A Popup , TextBox , TextBox Popup

<TextBox Name="textBox"
         Text="Popup On Mouse Over"
         HorizontalAlignment="Left"/>
<Popup PlacementTarget="{Binding ElementName=textBox}"
       Placement="Bottom">
    <Popup.IsOpen>
        <MultiBinding Mode="OneWay" Converter="{StaticResource BooleanOrConverter}">
            <Binding Mode="OneWay" ElementName="textBox" Path="IsMouseOver"/>
            <Binding RelativeSource="{RelativeSource Self}" Path="IsMouseOver" />
        </MultiBinding>
    </Popup.IsOpen>
    <StackPanel>
        <TextBox Text="Some Text.."/>
        <DatePicker/>
    </StackPanel>
</Popup>

BooleanOrConverter

public class BooleanOrConverter : IMultiValueConverter
{
    public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        foreach (object booleanValue in values)
        {
            if (booleanValue is bool == false)
            {
                throw new ApplicationException("BooleanOrConverter only accepts boolean as datatype");
            }
            if ((bool)booleanValue == true)
            {
                return true;
            }
        }
        return false;
    }
    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotSupportedException();
    }
}


DataGrid, . Popup DataTemplates DataGridTemplateColumn, DataGridCell Template. . SelectionMode = "Single" SelectionUnit = "Cell" DataGrid

<DataGrid SelectionMode="Single"
          SelectionUnit="Cell"
          ...>
    <DataGrid.CellStyle>
        <Style TargetType="DataGridCell">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type DataGridCell}">
                        <Grid>
                            <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
                                <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                            </Border>
                            <Popup PlacementTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                                   Placement="Right"
                                   IsOpen="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=IsSelected}">
                                <StackPanel>
                                    <TextBox Text="Some Text.."/>
                                    <DatePicker/>
                                </StackPanel>
                            </Popup>
                        </Grid>                                
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>    
    </DataGrid.CellStyle>
    <!--...-->
</DataGrid>
+10

All Articles