CornerRadius on shape tooltips?

5 posts, 1 answers
  1. James
    James avatar
    30 posts
    Member since:
    Aug 2008

    Posted 02 Dec 2010 Link to this post

    It looks like a bug in System.Windows.DataTemplate, but I thought I'd ask here if you know a way around this bug:

    Assigning a ToolTipTemplate to an InformationLater requires that you pass it a DataTemplate (of course - for binding), but the DataTemplate tip does not support CornerRadius (it seems broken).

    <DataTemplate x:Key="CustomToolTipDataTemplate">
        <Border BorderBrush="Black" BorderThickness="2" CornerRadius="6" Background="#FDF2D4" MaxWidth="300">
            <Grid Margin="2">
                <Grid.RowDefinitions>
                    <RowDefinition Height="14" />
                    <RowDefinition Height="12" />
                    <RowDefinition Height="12" />
                    <RowDefinition Height="12" />
                    <RowDefinition Height="12" />
                    <RowDefinition Height="12" />
                    <RowDefinition Height="12" />
                </Grid.RowDefinitions>
                <TextBlock Grid.Row="0" FontWeight="Bold" FontFamily="Trebuchet MS" FontSize="12" Text="{Binding Converter={StaticResource ExtendedDataConverter}, ConverterParameter='NAME', StringFormat=County: {0}}" />
                <TextBlock Grid.Row="1" FontWeight="Bold" FontFamily="Trebuchet MS" FontSize="10" Text="{Binding Converter={StaticResource ExtendedDataConverter}, ConverterParameter='PAT_EST', StringFormat='Paternity Establishment Percentage: {0:0.##}'}" />
                <TextBlock Grid.Row="2" FontFamily="Trebuchet MS" FontSize="10" Text="Percent of Cases with Orders: 87" />
                <TextBlock Grid.Row="3" FontFamily="Trebuchet MS" FontSize="10" Text="Percent of Current Collected: 91" />
                <TextBlock Grid.Row="4" FontFamily="Trebuchet MS" FontSize="10" Text="Percent of Cases Paying Arrears: 84" />
                <TextBlock Grid.Row="5" FontFamily="Trebuchet MS" FontSize="10" Text="Medical Support Ratio: 74" />
                <TextBlock Grid.Row="6" FontFamily="Trebuchet MS" FontSize="10" Text="Cost Effectiveness Ratio: 96" />
            </Grid>
        </Border>
    </DataTemplate>
     
    However, if I omit ToolTipTemplate and use ToolTipservice to specify this and call a ControlTemplate for the tip, CornerRadius works fine!

    <ToolTipService.ToolTip>
        <ToolTip Template="{StaticResource ToolTipTemplateXX}" HasDropShadow="True">
            <ToolTip.Content>
                <TextBlock
                    Text="This is a test"
                    FontFamily="Georgia" FontSize="14" TextWrapping="Wrap"/>
            </ToolTip.Content>
        </ToolTip>
    </ToolTipService.ToolTip>

    <ControlTemplate x:Key="ToolTipTemplateXX">
        <Border BorderBrush="Black" BorderThickness="2" CornerRadius="6" Background="#FDF2D4" MaxWidth="300">
            <Grid Margin="2">
                <Grid.RowDefinitions>
                    <RowDefinition Height="14" />
                    <RowDefinition Height="12" />
                    <RowDefinition Height="12" />
                    <RowDefinition Height="12" />
                    <RowDefinition Height="12" />
                    <RowDefinition Height="12" />
                    <RowDefinition Height="12" />
                </Grid.RowDefinitions>
                <TextBlock Grid.Row="0" FontWeight="Bold" FontFamily="Trebuchet MS" FontSize="12" Text="County: Centre" />
                <TextBlock Grid.Row="1" FontWeight="Bold" FontFamily="Trebuchet MS" FontSize="10" Text="Paternity Establishment Percentage: 98" />
                <TextBlock Grid.Row="2" FontFamily="Trebuchet MS" FontSize="10" Text="Percent of Cases with Orders: 87" />
                <TextBlock Grid.Row="3" FontFamily="Trebuchet MS" FontSize="10" Text="Percent of Current Collected: 91" />
                <TextBlock Grid.Row="4" FontFamily="Trebuchet MS" FontSize="10" Text="Percent of Cases Paying Arrears: 84" />
                <TextBlock Grid.Row="5" FontFamily="Trebuchet MS" FontSize="10" Text="Medical Support Ratio: 74" />
                <TextBlock Grid.Row="6" FontFamily="Trebuchet MS" FontSize="10" Text="Cost Effectiveness Ratio: 96" />
            </Grid>
        </Border>
    </ControlTemplate>

    Any idea why this is or how to work around it easily?

    Thanks!
  2. Answer
    Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 07 Dec 2010 Link to this post

    Hello James,

    You can use the ToolTipStyle property to specify the Template of tooltip. For this case you should specify the Path property as ExtendedData for binding.
    The sample code is below.
    <Window x:Class="WpfApplication1.MainWindow"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                 xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                 mc:Ignorable="d"
                 d:DesignHeight="300" d:DesignWidth="300">
        <Window.Resources>
            <ResourceDictionary>
                <telerik:ExtendedDataConverter x:Key="ExtendedDataConverter" />
                <ControlTemplate x:Key="CustomToolTipTemplate">
                    <Border BorderBrush="Black" BorderThickness="2" CornerRadius="6" Background="#FDF2D4" MaxWidth="300">
                        <Grid Margin="2">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="14" />
                                <RowDefinition Height="12" />
                                <RowDefinition Height="12" />
                                <RowDefinition Height="12" />
                                <RowDefinition Height="12" />
                                <RowDefinition Height="12" />
                                <RowDefinition Height="12" />
                            </Grid.RowDefinitions>
                            <TextBlock Grid.Row="0" FontWeight="Bold" FontFamily="Trebuchet MS" FontSize="12" Text="{Binding Path=ExtendedData, Converter={StaticResource ExtendedDataConverter}, ConverterParameter='NAME', StringFormat=County: {0}}" />
                            <TextBlock Grid.Row="1" FontWeight="Bold" FontFamily="Trebuchet MS" FontSize="10" Text="{Binding Path=ExtendedData, Converter={StaticResource ExtendedDataConverter}, ConverterParameter='PAT_EST', StringFormat='Paternity Establishment Percentage: {0:0.##}'}" />
                            <TextBlock Grid.Row="2" FontFamily="Trebuchet MS" FontSize="10" Text="Percent of Cases with Orders: 87" />
                            <TextBlock Grid.Row="3" FontFamily="Trebuchet MS" FontSize="10" Text="Percent of Current Collected: 91" />
                            <TextBlock Grid.Row="4" FontFamily="Trebuchet MS" FontSize="10" Text="Percent of Cases Paying Arrears: 84" />
                            <TextBlock Grid.Row="5" FontFamily="Trebuchet MS" FontSize="10" Text="Medical Support Ratio: 74" />
                            <TextBlock Grid.Row="6" FontFamily="Trebuchet MS" FontSize="10" Text="Cost Effectiveness Ratio: 96" />
                        </Grid>
                    </Border>
                </ControlTemplate>
                <Style x:Key="CustomToolTipStyle" TargetType="ToolTip">
                    <Setter Property="Template" Value="{StaticResource CustomToolTipTemplate}"/>
                </Style>
            </ResourceDictionary>
        </Window.Resources>
      <Grid>
            <telerik:RadMap Name="radMap">
                <telerik:RadMap.Provider>
                    <telerik:OpenStreetMapProvider />
                </telerik:RadMap.Provider>
                <telerik:InformationLayer Name="informationLayer">
                    <telerik:InformationLayer.Reader>
                        <telerik:MapShapeReader Source="/WpfApplication1;component/usa_st" ToolTipStyle="{StaticResource CustomToolTipStyle}"/>
                    </telerik:InformationLayer.Reader>
                </telerik:InformationLayer>
            </telerik:RadMap>
        </Grid>
    </Window>

    All the best,
    Andrey Murzov
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for WPF
  3. UI for WPF is Visual Studio 2017 Ready
  4. James
    James avatar
    30 posts
    Member since:
    Aug 2008

    Posted 07 Dec 2010 Link to this post

    I get a casting error when I try that:

    Unable to cast object of type 'MS.Internal.NamedObject' to type 'System.Windows.FrameworkTemplate'.
  5. James
    James avatar
    30 posts
    Member since:
    Aug 2008

    Posted 07 Dec 2010 Link to this post

    I double-checked my code and it looks fine. Still getting the casting error. Here's what I have:

        <Window.Resources>
            <ResourceDictionary>
                <telerik:ExtendedDataConverter x:Key="ExtendedDataConverter" />
                <Style x:Key="CustomToolTipStyle" TargetType="ToolTip">
                    <Setter Property="Template" Value="{StaticResource ToolTipTemplateCounty}"/>
                </Style>
                <ControlTemplate x:Key="ToolTipTemplateCounty">
                    <Border BorderBrush="Black" BorderThickness="2" CornerRadius="4" Background="#FDF2D4">
                        <Grid Margin="2">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="14" />
                                <RowDefinition Height="12" />
                                <RowDefinition Height="12" />
                                <RowDefinition Height="12" />
                                <RowDefinition Height="12" />
                                <RowDefinition Height="12" />
                                <RowDefinition Height="12" />
                            </Grid.RowDefinitions>
                            <TextBlock Grid.Row="0" FontWeight="Bold" FontFamily="Trebuchet MS" FontSize="12" Text="{Binding Path=ExtendedData, Converter={StaticResource ExtendedDataConverter}, ConverterParameter='NAME', StringFormat=County: {0}}" />
                            <TextBlock Grid.Row="1" FontWeight="Bold" FontFamily="Trebuchet MS" FontSize="10" Text="{Binding Path=ExtendedData, Converter={StaticResource ExtendedDataConverter}, ConverterParameter='CURR_COLL', StringFormat='Percent of Current Collected: {0:0.##}'}" />
                            <TextBlock Grid.Row="2" FontFamily="Trebuchet MS" FontSize="10" Text="Percent of Cases with Orders: 87" />
                            <TextBlock Grid.Row="3" FontFamily="Trebuchet MS" FontSize="10" Text="Paternity Establishment Percentage: 91" />
                            <TextBlock Grid.Row="4" FontFamily="Trebuchet MS" FontSize="10" Text="Percent of Cases Paying Arrears: 84" />
                            <TextBlock Grid.Row="5" FontFamily="Trebuchet MS" FontSize="10" Text="Medical Support Ratio: 74" />
                            <TextBlock Grid.Row="6" FontFamily="Trebuchet MS" FontSize="10" Text="Cost Effectiveness Ratio: 96" />
                        </Grid>
                    </Border>
                </ControlTemplate>
    ...

    And then:

                <telerik:RadMap x:Name="RadMap1"
                        Grid.Row="2"
                        CenterChanged="ReCenterMap"
                        Background="White"
                        BorderBrush="Black"
                        BorderThickness="0"                       
                        UseDefaultLayout="False"
                        MouseClickMode="None" MapMouseClick="RadMap1_MapMouseClick"
                        MouseDoubleClickMode="None" Grid.RowSpan="1">
                    <telerik:RadMap.Provider>
                        <telerik:EmptyProvider MinZoomLevel="6" MaxZoomLevel="8" />
                    </telerik:RadMap.Provider>
                    <telerik:InformationLayer x:Name="InformationLayer">
                    <telerik:InformationLayer.Reader>
                        <telerik:MapShapeReader Source="Data/Pennsylvania.shp"
                                                DataSource="Data/PA_10_2010.dbf"
                                                ToolTipStyle="{StaticResource CustomToolTipStyle}" />
                    </telerik:InformationLayer.Reader>
    ...

    Same error results. It seems to have a problem with this:

    <Setter Property="Template" Value="{StaticResource ToolTipTemplateCounty}"/>


  6. James
    James avatar
    30 posts
    Member since:
    Aug 2008

    Posted 07 Dec 2010 Link to this post

    Doh! My fault. The style had to come before the template. All is well. Thanks!
Back to Top
UI for WPF is Visual Studio 2017 Ready