当前位置:网站首页>C# TextBlock 上标
C# TextBlock 上标
2022-08-04 14:49:00 【林德熙】
我需要做一个函数,显示 x^2 ,但是看起来用 TextBlock 做的不好看。 我用 WPF 写的上标看起来不好看,但是最后有了一个简单方法让他好看。 本文告诉大家如何做一个好看的上标。
一开始做的方法:
把下面代码写在页面里,使用对齐是上面,改变字号,于是看起来就是上标。
<TextBlock x:Name="TextBlock">
<Run Text="y=x"></Run>
<Run Text="2" BaselineAlignment="TextTop"
FontSize="8"></Run>
</TextBlock>于是看起来:
其实已经可以了,但是发现距离很大,那么如何让距离变小?
我找了很久,发现可以在 xaml.cs 上写。
var textBlock = TextBlock;
textBlock.Inlines.Add(new Run("y = "));
textBlock.Inlines.Add(new Run("x"));
Run run=new Run();
run.FontSize = 7;
run.BaselineAlignment = BaselineAlignment.TextTop;
run.Text = "2";
textBlock.Inlines.Add(run);代码一样,但是写的地方不一样,可以看到现在的上标就好看了。
UWP 上标也一样。为什么写在 Xaml 间隔会那么大,是不是WR弄的?其实试试下面代码,注意不要格式化,直接写的样子和我的一样试试。
<TextBlock x:Name="TextBlock">
<TextBlock.Inlines>
<Run Text="y=x"/><Run Text="2" BaselineAlignment="TextTop"
FontSize="8"/>
</TextBlock.Inlines>
</TextBlock>原因就是Run写在两行,会把换行给记下,于是间隔就大了,写在一起的Run就不会出现这个距离。
但是我的 格式化会把Run放在下一行,所以可能我这里看的好的,在你这就会换行,看起来上标就有了距离。
我把他传上 csdn ,大家可以下载来验证。
边栏推荐
- leetcode: 251. Expanding 2D Vectors
- 基于 Next.js实现在线Excel
- [Problem solving] QT update component appears "To continue this operation, at least one valid and enabled repository is required"
- Win10无法访问移动硬盘怎么解决
- Notes for xpath getting node with namespace
- 如何和程序员谈恋爱
- 郑轻新生校赛和中工选拔赛题解
- 1401 - Web technology 】 【 introduction to graphical Canvas
- centos7安装mysql急速版
- Technology sharing | Mini program realizes audio and video calls
猜你喜欢

This week to discuss the user experience: Daedalus Nemo to join Ambire, explore the encryption of the ocean

leetcode: 212. Word Search II

用于X射线聚焦的复合折射透镜

物联网应用发展趋势

Bluetooth Technology|In the first half of the year, 1.3 million charging piles were added nationwide, and Bluetooth charging piles will become the mainstream of the market

基于数据库实现分布式锁

leetcode:241. 为运算表达式设计优先级

基本介绍PLSQL

Lixia Action | Kyushu Yunzhang Jinnan: Open source is not a movement for a few people, popularization is the source

一看就会的Chromedriver(谷歌浏览器驱动)安装教程
随机推荐
xampp安装包含的组件有(php,perl,apche,mysql)
Oracle 数据库用户创建、重启、导入导出
[The Art of Hardware Architecture] Study Notes (1) The World of Metastability
centos7安装mysql急速版
Android Sqlite3基本命令
B. Construct a simple sequence (greedy)
Notes for xpath getting node with namespace
饿了么智能头盔专利获授权,进一步提升骑手安全保障
vim common operation commands
特殊品种的二次开户验资金额
爬虫——selenium基本使用、无界面浏览器、selenium的其他用法、selenium的cookie、爬虫案例
Almost all known protein structures in the world are open sourced by DeepMind
RS|哨兵二号(.SAFE格式)转tif格式
ping的原理
第十六章 源代码文件 REST API 教程(一)
什么,你告诉我?作用域也分种类?
郑轻新生校赛和中工选拔赛题解
How to write SQL statements: the usage of Update, Case, and Select together
用了TCP协议,就一定不会丢包吗?
爬虫——动作链、xpath、打码平台使用