我有这个 XAML:
<TextBlock Text="Message with unicode char: ⓘ"/>
有什么方法可以将 unicode 字符 ⓘ
转换为共享资源(如常量或 StaticResource
)?
我尝试过的
方法一
这工作正常,但它需要一个有效的绑定(bind)才能工作:
<Grid>
<Grid.Resources>
<system:String x:Key="ToolTipChar">{0} ⓘ</system:String>
</Grid.Resources>
<TextBlock Text="{Binding MyText, StringFormat={StaticResource ToolTipChar}}"/>
</Grid>
在后面的代码中:
public string MyText { get; set; } = "Message with unicode char: ";
方法二
这个方法似乎可行,但运气不好:
<Grid>
<Grid.Resources>
<system:String x:Key="ToolTipChar">{0} ⓘ</system:String>
</Grid.Resources>
<TextBlock Text="{Binding Nothing, FallbackValue='Message with unicode char: ', StringFormat={StaticResource ToolTipChar}}"/>
</Grid>
最佳答案
如果我正确理解你的问题,这应该有效:
<Window.Resources>
<s:String x:Key="ToolTipChar">{0}ⓘ</s:String>
</Window.Resources>
...
<TextBlock Text="{Binding Source='Message with unicode char:', StringFormat={StaticResource ToolTipChar}}" />
关于c# - WPF:如何将 Unicode 字符转移到共享资源中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47754636/