WPF ToolTip Style with dynamic LayoutTransform

Posted by NoOne on Stack Overflow See other posts from Stack Overflow or by NoOne
Published on 2012-12-07T13:46:38Z Indexed on 2012/12/07 23:05 UTC
Read the original article Hit count: 649

Filed under:
|
|
|

I have an app that scales it's UI and I want to scale the ToolTips with it. I have tried doing this:

<Style TargetType="{x:Type ToolTip}">
    <Setter Property="LayoutTransform" Value="{DynamicResource scaleTransf}"/>
    ...
</Style>

...where scaleTransf is a resource that I change via code:

Application.Current.Resources["scaleTransf"] = new ScaleTransform(...);

Most of the ToolTips do get scaled in size but some of them that are created by C# code don't get scaled. I've checked and it seems that I don't set their Style or LayoutTransform by code, so I don't really understand what is going wrong... Moreover, I have the impression that the above XAML code worked fine a few days ago. :(

Is there sth I can do to make it work all the time without setting the LayoutTransform in code-behind?

EDIT : The ToolTips that don't change scale are the ones that have become visible before.


EDIT2 : Extra code:

<ScaleTransform x:Key="scaleTransf" ScaleX="1" ScaleY="1"/>

I have also tried this:

Application.Current.Resources.Remove("scaleTransf");
Application.Current.Resources.Add("scaleTransf", new ScaleTransform(val, val));

EDIT3 : My attempt to solve this using a DependencyProperty:

In MainWindow.xaml.cs :

    public static readonly DependencyProperty TransformToApplyProperty = DependencyProperty.Register("TransformToApply", typeof(Transform), typeof(MainWindow));
    public Transform TransformToApply
    {
        get { return (Transform)this.GetValue(TransformToApplyProperty); }
    }

Somewhere in MainWindow, in response to a user input:

this.SetValue(TransformToApplyProperty, new ScaleTransform(val, val));

XAML Style:

<Style TargetType="{x:Type ToolTip}">
    <Setter Property="LayoutTransform" Value="{Binding TransformToApply, ElementName=MainWindow}"/>
...

Using this code, not a single one of the ToolTips seem to scale accordingly.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about dynamic