How to organize something like a tooltip for a shape in which you can change the color, size and name (name). I'm about to imagine how to do it, but I'm afraid that this will be another crutch that will work every other time. 
- And what exactly do you want? Formatting? Data binding? What does not come out? - VladD February
- @VladD is both, that is, formatting and data binding, and also so that when I moved the cursor to the tooltip itself, to change the parameter, the tooltip would not disappear. - alex-rudenkiy 5:53 pm
|
1 answer
With formatting and binding is simple. Here is a snippet:
<TextBlock Text="I am long text"> <TextBlock.ToolTip> <ToolTip Background="LightCyan" Padding="0"> <Border BorderBrush="DarkCyan" BorderThickness="3" Padding="5"> <StackPanel Orientation="Vertical"> <TextBlock Text="{Binding A, StringFormat='A = {0}'}"/> <TextBlock Text="{Binding B, StringFormat='B = {0}'}"/> </StackPanel> </Border> </ToolTip> </TextBlock.ToolTip> </TextBlock> To convert from a string to a background color, you can use such a converter:
class StringToBrushConverter : IValueConverter { BrushConverter converter = new BrushConverter(); public object Convert(object value, Type targetType, object p, CultureInfo culture) { try { return converter.ConvertFrom(value); } catch { return null; } } public object ConvertBack(object value, Type targetType, object p, CultureInfo culture) { throw new NotSupportedException(); } } <TextBox Width="70"> <TextBox.ToolTip> <ToolTip Background="{Binding PlacementTarget.Text, RelativeSource={RelativeSource Self}, Converter={StaticResource S2B}, TargetNullValue=Yellow}" MinWidth="50"> <TextBlock Text="{Binding PlacementTarget.Text, RelativeSource={RelativeSource FindAncestor, AncestorType=ToolTip}, StringFormat='Color = {0}'}"/> </ToolTip> </TextBox.ToolTip> </TextBox> - But what about the color change in shape with onchange? Well, in the sense that when you change the color in the string so that it immediately changes to the color that I entered. And how to make the tooltip appear in the middle of the top shape? - alex-rudenkiy February
- @Alex_Rudenkiy: Placement is for the exact location. If you want something completely exotic, there is Custom for it. - VladD February
- @Alex_Rudenkiy: I think that the color can be changed by binding, as usual. - VladD February
- but how to work with the binding, I just tried to figure it out, but it didn’t work, can you tell me how to do it all? - alex-rudenkiy
- When I change the text in the tooltip in the onchange event, I can get the text, then apply the received text to the object that caused the tooltip, but it seems to me that this can be done more easily - alex-rudenkiy
|