rem
rem

Reputation: 17055

Is it possible to assign ToolTip text (containing non-latin characters) in a Control Template of a WPF custom control?

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.)

Upvotes: 1

Views: 1127

Answers (1)

Aviad P.
Aviad P.

Reputation: 32639

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.

Upvotes: 2

Related Questions