views:

238

answers:

1

In a WPF app I have a custom control. I would like the ToolTip for objects, derived from this custom control, depends on a value of one of the attributes of this custom control.

Is it possible to declare it in a Control Template of this custom control?

Something like:

<ControlTemplate>
??? // <!--XAML ToolTip declaration -->
...
<ControlTemplate.Triggers>                    
   <Trigger Property="MyProperty" Value="FirstValue">
     <Setter ...???  />  // <!--XAML ToolTip text assignment -->
   </Trigger>
   ... 
   <Trigger Property="MyProperty" Value="SecondValue">
     <Setter ...???  />  // <!--XAML ToolTip text assignment -->
   </Trigger>  
</ControlTemplate.Triggers>
</ControlTemplate> 

Edited (added):

I have found the solution:

   <MultiTrigger>
     <MultiTrigger.Conditions>
       <Condition Property="IsMouseOver" Value="True" />
       <Condition Property="MyProperty" Value="FirstValue" />
     </MultiTrigger.Conditions>
     <Setter TargetName="PART_Backgr" Property="ToolTip" Value="Available"/>
   </MultiTrigger>

   <MultiTrigger>
     <MultiTrigger.Conditions>
       <Condition Property="IsMouseOver" Value="True" />
       <Condition Property="MyProperty" Value="SecondValue" />
     </MultiTrigger.Conditions>
     <Setter TargetName="PART_Backgr" Property="ToolTip" Value="Sold"/>
   </MultiTrigger> 

It is working excellent. But one problem remained: In fact Value="Available" and others such values should contain non-latin characters (the application is localized in Russian language). When I am trying to compile it with Value="Свободно", I get en error: 'Invalid character in the given encoding.' XML is not valid.

What solution could be to this problem? Maybe I could change somewhere the encoding by which Generic.xaml page compiles? Or change XAML code somehow? (In fact, in every window I have lots of non-latin characters in XAML and everything compiles OK. But, maybe, the problem is in the way they used.)

+1  A: 

Does this not work?

<ControlTemplate.Triggers>                    
    <Trigger Property="MyProperty" Value="FirstValue">
        <Setter Property="ToolTip" Value="..."/>
    </Trigger>
</ControlTempalte.Triggers>

To try and address your other issue, the following works for me without any special changes:

<TextBlock Text="Свободно" ToolTip="Свободно"/>

I copied and pasted that text from your question into my XAML code.

Aviad P.
Aviad, thank you! In fact, you put your post while I was typing mine - they are almost similar. Please, have a look at my new problem (in updated question) - maybe you could help me with it also.
rem
And your suggestion is OK. +1
rem
Yes, it works for me also. But only in exact way as you suggested and in xaml of general wpf window. If I try to use Property="ToolTip" Value="Свободно" in a Setter tag of a ControlTemplate xaml (Generic.xaml window), I get that mentioned error.
rem
Maybe there is a way to use ToolTip="Свободно" rather than Property="ToolTip" Value="Свободно" approach in ControlTemplate xaml also? (I don't know how it is possible)
rem
Works for me inside a style as well, inside a control template inside a custome control, everywhere. One thing tho, when I put it into the Generic.xaml of my custom control, visual studio warned me that it contained Unicode and asked me if I wanted to save it as Unicode, when I answered yes, everything was ok again.
Aviad P.
Your information is encouraging. I will search where my problem is. (Unfortunately my Visual Studio asks me nothing - just tries to compile and gives an error). Thanks, I will dig into VS settings also.
rem
Aviad, thanks to your encouraging, I managed to do it. Though, only in such a way: Property="ToolTip" Value="Свободно" So, I succeeded only using unicode hex text representation for custom control declaration. I don't know why my VS2008 behaves like this. But, nevertheless, the problem is solved! Thank you very much!
rem
Ouch, that looks painful :) keep looking, maybe you need to set the locale of your visual studio to en-US, instead of russian maybe, for it to work correctly, there must be a better way.
Aviad P.