Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Is is possible to assign tool tip to a shape class (Read 1399 times)
ashar11
Junior Member
**
Offline


I Love MindFusion!

Posts: 56
Joined: Jun 29th, 2017
Is is possible to assign tool tip to a shape class
Jul 21st, 2018 at 9:41am
Print Post  
Hi,
    I have shapes in a ListBox on a different window(other than having diagram control) and from there i drag them on diagram, is it possible to assign tooltip to the shape existing in ListBox because shape does not have any tooltip property. Code is given below

          Shape customShape = new Shape(new[]{
             new LineTemplate(0, 0, 0, 100),
             new LineTemplate(0, 100, 100, 100),
             new LineTemplate(100, 100, 100, 0),
             new LineTemplate(100, 0, 0, 0)
             }, 0, "ABC");

            customShape.Image = new BitmapImage(new Uri(@"abc.png"));
            customShape.Id = "ABC Image";
        //-----tooltip not available----//    customShape.tootip= "ABC Image";

     //--comment// toolbar is System.Windows.Controls.LisBox
                        
     toolbar.ItemsSource = new[] { customShape};
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: Is is possible to assign tool tip to a shape class
Reply #1 - Jul 23rd, 2018 at 12:40pm
Print Post  
Hi,

You could show tooltips by setting Tooltip property from ShapeListBox' item template -

Code
Select All
<Window.Resources>
    <ResourceDictionary>
		<diag:DoubleToRectConverter x:Key="rectConverter" />
		<global:ShapeToolTipConverter x:Key="shapeToolTipConverter" />
...
<diag:ShapeListBox x:Name="toolbar" Height="200">
	<diag:ShapeListBox.Template>
		<ControlTemplate TargetType="{x:Type diag:ShapeListBox}">
			<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
				<ListView x:Name="listView" ItemsSource="{TemplateBinding ItemsSource}">
					<ListView.ItemTemplate>
						<DataTemplate>
							<StackPanel Orientation="Horizontal" ToolTip="{Binding Mode=OneWay, Converter={StaticResource shapeToolTipConverter}}">
								<Border BorderThickness="3">
									<diag:ShapeNode
										diag:ShapeListBox.Shape="{Binding}"
										Bounds="{Binding ShapeSize, RelativeSource={RelativeSource AncestorType=diag:ShapeListBox}, Converter={StaticResource rectConverter}}"
										Brush="{Binding ShapeBrush, RelativeSource={RelativeSource AncestorType=diag:ShapeListBox}}" />
								</Border>
								<TextBlock Text="{Binding DisplayName}" VerticalAlignment="Center" TextAlignment="Center"/>
							</StackPanel>
						</DataTemplate>
					</ListView.ItemTemplate>
				</ListView>
			</Border>
		</ControlTemplate>
	</diag:ShapeListBox.Template>
</diag:ShapeListBox> 



The Shape class itself does not contain a tooltip property. You could derive from Shape to define the property, or keep some dictionary from shape ID to tooltip and return it from converter. This sample converter simply returns shape's DisplayName value as tooltip -

Code
Select All
class ShapeToolTipConverter : IValueConverter
{
	public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
	{
		var shape = value as Shape;
		if (shape != null)
			return shape.DisplayName;
		return "";
	}

	public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
	{
		throw new NotImplementedException();
	}
} 



Regards,
Slavcho
  
Back to top
 
IP Logged
 
ashar11
Junior Member
**
Offline


I Love MindFusion!

Posts: 56
Joined: Jun 29th, 2017
Re: Is is possible to assign tool tip to a shape class
Reply #2 - Jul 24th, 2018 at 8:27am
Print Post  
Thanks its working now.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint