tags:

views:

783

answers:

2

I have a wpf program in c# that has a combobox with various colors to choose from. It looks something like this

? Text

I am making a configurator that can change the color of certain texts in another program. So if the user opens the program and he doesn't like the description text color, he can open up the configurator and change the color. When the user chooses a color from the combobox the Text changes color. When the user hovers his mouse over the ? an image appears showing an image of the program with the changed text color. So far I can make the image of the program appear, but I can't make any text appear on top of it. This is what I have right now:

System.Windows.Controls.Image td = new System.Windows.Controls.Image(); BitmapImage myBitmapImage = new BitmapImage(); myBitmapImage.BeginInit(); myBitmapImage.UriSource = new Uri(Directory.GetCurrentDirectory() + "/Homepage.jpg"); myBitmapImage.DecodePixelWidth = 700; myBitmapImage.DecodePixelHeight = 590; myBitmapImage.EndInit(); td.Source = myBitmapImage;

        ToolTipService.SetPlacement(image1, System.Windows.Controls.Primitives.PlacementMode.Left);
        ToolTipService.SetToolTip(image1, td);
        ToolTipService.SetShowDuration(image1, 999999999);

How can I position text to appear on top of the tooltip image?

A: 

Try looking at the adorner layer. Basically the adorner layer allows you to display items without affecting the layout of the controls underneath.

strattonn
so how can I used it to help me in this situation? Thanks for the reply.
Jake
No, there is a simpler solution than this. See my answer.
Charlie
A: 

ToolTipService allows you to set the tool tip to be any content. So set it as a panel containing both an image and text. The following code accomplishes this:

TextBlock textBlock = new TextBlock();
textBlock.Foreground = Brushes.White;
textBlock.HorizontalAlignment = HorizontalAlignment.Center;
textBlock.VerticalAlignment = VerticalAlignment.Center;
textBlock.Text = "Overlaying Image Text";

Grid toolTipPanel = new Grid();
toolTipPanel.Children.Add(td);
toolTipPanel.Children.Add(textBlock);

ToolTipService.SetToolTip(image1, toolTipPanel);
Charlie
Thanks a lot Charlie. It works. Is there a way to position the text anywhere I want on the image? Thanks a lot for all your help.
Jake
Absolutely- the HorizontalAlignment and VerticalAlignment properties on the TextBlock are what you want. You can set them to left, right, top, bottom, etc. If you want absolute positioning (like X,Y coordinates), you will need to replace the Grid with a Canvas.
Charlie