Is there a ...">

WPF: How to transfer a Unicode character to a share?

I have this XAML:

<TextBlock Text="Message with unicode char: &#x24D8;"/>

Is there a way to shift the unicode character &#x24D8;to a shared resource (e.g. constant or StaticResource)?

What i tried

Method 1

This works fine, but a valid commitment is required to work:

<Grid>
    <Grid.Resources>
        <system:String x:Key="ToolTipChar">{0} &#x24D8;</system:String>
    </Grid.Resources>
    <TextBlock Text="{Binding MyText, StringFormat={StaticResource ToolTipChar}}"/>
</Grid>

And in the code behind:

public string MyText { get; set; } = "Message with unicode char: ";    

Method 2

This method seems to work, but no luck:

<Grid>
    <Grid.Resources>
        <system:String x:Key="ToolTipChar">{0} &#x24D8;</system:String>
    </Grid.Resources>
    <TextBlock Text="{Binding Nothing, FallbackValue='Message with unicode char: ', StringFormat={StaticResource ToolTipChar}}"/>
</Grid>
+4
source share
3 answers

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}}" />
+6
source

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 believe this is a little readable and easier to understand than putting a replacement token directly in a resource string.

+2
source

, , 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 - TextBlock, <TextBlock.Inlines> . Inlines , :

screenshot

+2

Source: https://habr.com/ru/post/1690555/


All Articles