WPF: How to shift Unicode character into a shared resource?

后端 未结 3 358
生来不讨喜
生来不讨喜 2021-01-18 20:17

I have this XAML:


Is there some way to shift that unicode character

相关标签:
3条回答
  • 2021-01-18 20:58

    Another alternative which doesn't involve binding is to use TextBlock.Inlines

    <my:String x:Key="TooltipSign">&#x24D8;</my:String>
    
    <TextBlock HorizontalAlignment="Right" Margin="10">
        <Run Text="Message with unicode char:"/>
        <Run Text="{StaticResource TooltipSign}" 
             FontWeight="Bold" Foreground="Orange" Background="Black"/>
    </TextBlock>
    

    TextBlock.Inlines is a content property of TextBlock, so <TextBlock.Inlines> tag can be omitted. Inlines provide additional decorating possibilities, like coloring part of the text:

    0 讨论(0)
  • 2021-01-18 21:01

    This will also work:

    <Window.Resources>
        <system:String x:Key="ToolTipChar">&#x24D8;</system:String>
    </Window.Resources>
    ...
    <TextBlock Text="{Binding StringFormat='Message with unicode char: {0}', 
                              Source={StaticResource ToolTipChar}}" />
    

    I find it slightly more readable, and easier to understand, than putting the replacement token directly in the string resource.

    0 讨论(0)
  • 2021-01-18 21:11

    If I understand your question correctly, this should work:

    <Window.Resources>
        <s:String x:Key="ToolTipChar">{0}&#x24D8;</s:String>
    </Window.Resources>
    ...
    <TextBlock Text="{Binding Source='Message with unicode char:', StringFormat={StaticResource ToolTipChar}}" />
    
    0 讨论(0)
提交回复
热议问题