Problems with resource tooltips

2 posts, 1 answers
  1. Håkan
    Håkan avatar
    183 posts
    Member since:
    May 2011

    Posted 17 Apr 2014 Link to this post

    Hi!

    I have extended the Resource class used in the ScheduleView to add a few properties.
    Among them is ToolTip, a string property I use to create a more advanced multiline tooltip.

    I group appointments by resources in the ScheduleView.
    My group header for resources is a RadButton and looks like this:
    <telerik:RadButton Background="{x:Null}" BorderBrush="{StaticResource Control_BorderBrush}" Command="{Binding EmployeeResourceCommand, Source={StaticResource ViewModel}}" CommandParameter="{Binding Name}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
                                    <telerik:RadButton.Content>
                                        <Grid>
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="14" />
                                                <RowDefinition Height="Auto" />
                                                <RowDefinition Height="*" />
                                            </Grid.RowDefinitions>
                                            <Grid.Resources>
                                                <Style TargetType="TextBlock" BasedOn="{StaticResource DefaultTextBlock}">
                                                    <Setter Property="VerticalAlignment" Value="Center" />
                                                    <Setter Property="TextWrapping" Value="NoWrap" />
                                                </Style>
                                            </Grid.Resources>
                                            <StackPanel Orientation="Horizontal" Grid.Row="0" HorizontalAlignment="Left">
                                                <TextBlock Text="*" FontWeight="Bold" Padding="5,0,0,0" Visibility="{Binding Name.IsModified, Converter={StaticResource VisibilityConverter}}" />
                                                <TextBlock Text="{Binding Name}" FontWeight="{Binding Name.IsModified, Converter={StaticResource BooleanFontWeightConverter}}" Visibility="{Binding ShowSummary, Source={StaticResource ViewModel}, Converter={StaticResource VisibilityConverter}}" Padding="5,0,5,0" />
                                                <TextBlock Text="{Binding Name}" FontWeight="{Binding Name.IsModified, Converter={StaticResource BooleanFontWeightConverter}}" Foreground="{Binding Name, Converter={StaticResource EmployeeResourceWorkTimeColorConverter}}" Visibility="{Binding ShowSummary, Source={StaticResource ViewModel}, Converter={StaticResource VisibilityConverter}, ConverterParameter='inverse'}" Padding="5,0,5,0" />
                                            </StackPanel>
                                            <StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Center" Height="14" Margin="5,0,5,0" Visibility="{Binding ShowSummary, Source={StaticResource ViewModel}, Converter={StaticResource VisibilityConverter}}">
                                                <TextBlock Text="{Binding Name.PlannedMinutes, Converter={StaticResource MinutesToTimeSpanConverter}}" Foreground="{Binding Name, Converter={StaticResource EmployeeResourceWorkTimeColorConverter}}" />
                                                <TextBlock Text="/" Foreground="{Binding Name, Converter={StaticResource EmployeeResourceWorkTimeColorConverter}}" />
                                                <TextBlock Text="{Binding Name.WorkTimeMinutes, Converter={StaticResource MinutesToTimeSpanConverter}}" Foreground="{Binding Name, Converter={StaticResource EmployeeResourceWorkTimeColorConverter}}" />
                                            </StackPanel>
                                            <ToolTipService.ToolTip>
                                                <ToolTip Content="{Binding Name.ToolTip}" Style="{StaticResource MultiLine_ToolTip}" />                                           
                                            </ToolTipService.ToolTip>
                                        </Grid>
                                    </telerik:RadButton.Content>
                                </telerik:RadButton>

    As you can see I use ToolTipService.ToolTip at the bottom. And when I only set the content as above, binding it to the ToolTip property of my extended class, it works fine!
    But now I want to include an Image inside the tooltip so I tried this:
    <ToolTipService.ToolTip>
                                                <ToolTip Style="{StaticResource MultiLine_ToolTip}">
                                                    <ToolTip.Content>
                                                        <StackPanel Orientation="Vertical">
                                                            <Image Source="{Binding Name.Image, Converter={StaticResource ByteArrayToBitmapImageConverter}}" Height="32" Width="32" />
                                                            <TextBlock Text="{Binding Name.ToolTip}" />
                                                        </StackPanel>
                                                    </ToolTip.Content>
                                                </ToolTip>
                                            </ToolTipService.ToolTip>

    But now, only the default tooltip with DisplayName will be shown.
    I even tried just a simple TextBlock with a hard coded text, but it does not show up.
    <ToolTipService.ToolTip>
        <ToolTip>
            <ToolTip.Content>
                <TextBlock Text="FOO" />
            </ToolTip.Content>
        </ToolTip>
    </ToolTipService.ToolTip>



    As soon as I use the ToolTip.Content tag instead of binding the content it fails.


    What am I doing wrong?

    Regards,
    Håkan



  2. Answer
    Kalin
    Admin
    Kalin avatar
    1209 posts

    Posted 17 Apr 2014 Link to this post

    Hello Håkan,

    You can achieve the desired by using the ContentTemplate property of the ToolTip in order to apply the desired Template. However please note that you would also need to bind the Content property correctly so the ToolTip receives the correct object containing the desired information. Check the attached sample project which demonstrates the exact approach.

    Hope this will help you to achieve the required.

    Regards,
    Kalin
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. DevCraft banner
Back to Top