问题描述
我想根据文字为文本块中的"运行"项目的前景着色。 例如,如果"DisplayName",在下面的代码示例中是"管理员"然后我希望前景是红色的,否则是白色的。 有没有
a的方法呢?
< TextBlock Grid.Row =" 1" TextWrapping = QUOT;包覆与QUOT;前景= QUOT;白色" FontFamily =" Myriad Pro"字号= QUOT 18 QUOT;
fontWeight设置= QUOT; SemiBold" Grid.Column = QUOT 1 QUOT; VerticalAlignment = QUOT;中心"的HorizontalAlignment = QUOT;拉伸">
< Run Text =" {x:Bind LocalDateTime,Converter = {StaticResource StringFormatConverter},
ConverterParameter ='{} {0:[HH \\\\\:mm tt] }"}" />
< Run Text =" {x:Bind DisplayName}" />
< Run Text =":" />
< Run Text =" {x:Bind ChatMessage}" />
< / TextBlock>
I would like to color the foreground of a Run item in a textblock based on the text. For instance if "DisplayName" in the code example below is "Admin" then I would like the foreground to be red, otherwise white. Is there a way to do this?
<TextBlock Grid.Row="1" TextWrapping="Wrap" Foreground="White" FontFamily="Myriad Pro" FontSize="18"
FontWeight="SemiBold" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Stretch"> <Run Text="{x:Bind LocalDateTime, Converter={StaticResource StringFormatConverter},
ConverterParameter='{}{0:[HH\\\\:mm tt]}'}" /> <Run Text="{x:Bind DisplayName}" /> <Run Text=": " /> <Run Text="{x:Bind ChatMessage}" /> </TextBlock>
这篇关于[C#] [UWP]设置TextBlock根据文本运行前景色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!