Reputation: 783
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?
Upvotes: 1
Views: 5046
Reputation: 15247
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);
Upvotes: 2
Reputation: 2002
Try looking at the adorner layer. Basically the adorner layer allows you to display items without affecting the layout of the controls underneath.
Upvotes: 0