青山依旧在

青山依旧在  - []

转载于:http://blog.itpub.net/13679130/viewspace-220262/

给代码(<Window x:Class="HelloWorld.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:HelloWorld" mc:Ignorable="d" FontSize="16" Title="HelloWorld - www.wpfsoft.com" Height="350" Width="500"> <WrapPanel> <TextBlock Text="这是一个TextBlock文字块" Margin="5"/> <TextBlock Text="粗体文字" FontWeight="Bold" Margin="5"/> <TextBlock Text="粗体文字" FontWeight="Light" Margin="5"/> <TextBlock Text="斜体文字" FontStyle="Italic" Margin="5"/> <TextBlock Text="微软雅黑" FontFamily="Microsoft YaHei UI" Margin="5"/> <TextBlock Text="大号字体" FontSize="30" Margin="5"/> <TextBlock Text="红色文字" Foreground="Red" Margin="5"/> <TextBlock Text="底色文字" Foreground="Yellow" Background="Red" Margin="5"/> <TextBlock Text="内间距文字" Foreground="Yellow" Background="Red" Padding="10" Margin="5"/> <TextBlock Background="LightGray" Height="25"> <Run Foreground="Red">这行文字</Run> <Run Foreground="Green">由三部分</Run> <Run Foreground="Blue">组成</Run> </TextBlock> <Grid Width="150" Height="100" Margin="5" Background="LightGoldenrodYellow"> <TextBlock Text="这段文字体现了文字的文本换行属性TextWrapping" TextWrapping="Wrap" Margin="10"/> </Grid> <!--使用Run--> <Grid> <TextBlock x:Name="textblock" Width="320" Height="100" FontSize="15" FontFamily="微软雅黑" FontWeight="Black" FontStretch="Condensed" Foreground="#dddddd" Background="Teal" TextAlignment="Center" TextWrapping="Wrap" TextTrimming="CharacterEllipsis" Margin="10" Padding="5" HorizontalAlignment="Left" VerticalAlignment="Center" LineHeight="30" ToolTip="《临江仙·滚滚长江东逝水》"> <Run Foreground="#CDB632" TextDecorations="Underline"> 滚滚长江东逝水,浪花淘尽英雄。是非成败转头空。青山依旧在,几度夕阳红。 </Run> <Run Text="白发渔樵江渚上,惯看秋月春风。一壶浊酒喜相逢。古今多少事,都付笑谈中。 "> </Run> </TextBlock> </Grid> </WrapPanel> </Window>)添加详细注释
09-24
以下是您提供的 **WPF 窗口 XAML 代码** 的完整版本,并为每一行或每一段添加了详细的中文注释,帮助理解各个属性和控件的作用。 --- ## 🧾 完整带详细注释的 XAML 代码 ```xml <Window x:Class="HelloWorld.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:HelloWorld" mc:Ignorable="d" FontSize="16" <!-- 设置整个窗口中默认字体大小 --> Title="HelloWorld - www.wpfsoft.com" <!-- 设置窗口标题 --> Height="350" <!-- 设置窗口高度 --> Width="500"> <!-- 设置窗口宽度 --> <!-- WrapPanel 是一个布局容器,内容会自动换行排列 --> <WrapPanel> <!-- TextBlock 是用于显示只读文本的控件 --> <TextBlock Text="这是一个TextBlock文字块" Margin="5"/> <!-- 显示普通文本 --> <TextBlock Text="粗体文字" FontWeight="Bold" Margin="5"/> <!-- 使用 Bold 样式显示粗体 --> <TextBlock Text="粗体文字" FontWeight="Light" Margin="5"/> <!-- 使用 Light 样式显示较细字体 --> <TextBlock Text="斜体文字" FontStyle="Italic" Margin="5"/> <!-- 斜体样式 --> <TextBlock Text="微软雅黑" FontFamily="Microsoft YaHei UI" Margin="5"/> <!-- 指定字体族为 Microsoft YaHei UI --> <TextBlock Text="大号字体" FontSize="30" Margin="5"/> <!-- 设置较大字号 --> <TextBlock Text="红色文字" Foreground="Red" Margin="5"/> <!-- 设置前景色为红色 --> <TextBlock Text="底色文字" Foreground="Yellow" Background="Red" Margin="5"/> <!-- 设置背景色和前景色 --> <TextBlock Text="内间距文字" Foreground="Yellow" Background="Red" Padding="10" Margin="5"/> <!-- 添加内边距(Padding) --> <!-- 下面是一个使用多个 Run 元素来展示不同样式的 TextBlock --> <TextBlock Background="LightGray" Height="25"> <Run Foreground="Red">这行文字</Run> <!-- 第一部分为红色 --> <Run Foreground="Green">由三部分</Run> <!-- 第二部分为绿色 --> <Run Foreground="Blue">组成</Run> <!-- 第三部分为蓝色 --> </TextBlock> <!-- Grid 布局中展示文本换行功能 --> <Grid Width="150" Height="100" Margin="5" Background="LightGoldenrodYellow"> <TextBlock Text="这段文字体现了文字的文本换行属性TextWrapping" TextWrapping="Wrap" <!-- 设置文本自动换行 --> Margin="10"/> </Grid> <!-- 复杂的 TextBlock 示例,包含多个 Run 和多种样式设置 --> <Grid> <TextBlock x:Name="textblock" <!-- 给 TextBlock 控件命名,便于在 C# 中访问 --> Width="320" <!-- 设置宽度 --> Height="100" <!-- 设置高度 --> FontSize="15" <!-- 字号设置为 15 --> FontFamily="微软雅黑" <!-- 字体设置为 微软雅黑 --> FontWeight="Black" <!-- 加粗为最重 --> FontStretch="Condensed" <!-- 字体压缩 --> Foreground="#dddddd" <!-- 文字颜色为浅灰色 --> Background="Teal" <!-- 背景色为青绿色 --> TextAlignment="Center" <!-- 文本居中对齐 --> TextWrapping="Wrap" <!-- 自动换行 --> TextTrimming="CharacterEllipsis" <!-- 超出时以字符省略号结尾 --> Margin="10" <!-- 设置外边距 --> Padding="5" <!-- 设置内边距 --> HorizontalAlignment="Left" <!-- 水平左对齐 --> VerticalAlignment="Center" <!-- 垂直居中对齐 --> LineHeight="30" <!-- 每行高度为 30 --> ToolTip="《临江仙·滚滚长江东逝水》"> <!-- 鼠标悬停时显示提示信息 --> <!-- 第一个 Run:带有下划线和黄色字体 --> <Run Foreground="#CDB632" TextDecorations="Underline"> 滚滚长江东逝水,浪花淘尽英雄。是非成败转头空。青山依旧在,几度夕阳红。 </Run> <!-- 第二个 Run:普通文字,无特殊装饰 --> <Run Text="白发渔樵江渚上,惯看秋月春风。一壶浊酒喜相逢。古今多少事,都付笑谈中。 "> </Run> </TextBlock> </Grid> </WrapPanel> </Window> ``` --- ## ✅ 注释总结说明 ### 🎨 文本样式相关属性: - `FontFamily`:指定使用的字体系列。 - `FontSize`:设置文本大小。 - `FontStyle`:控制是否为斜体。 - `FontWeight`:控制字体粗细。 - `Foreground`:设置文字的颜色。 - `Background`:设置背景颜色。 - `TextDecorations`:为文字添加装饰效果,如下划线、删除线等。 - `LineHeight`:设置每行的高度。 - `TextTrimming`:当文本超出区域时如何处理(例如省略号)。 ### 🧱 布局与格式属性: - `Margin`:设置组件与周围元素的距离。 - `Padding`:设置内容与边界的间距。 - `TextAlignment`:设置文本对齐方式(左对齐、右对齐、居中)。 - `TextWrapping`:设置文本是否自动换行。 - `Width / Height`:设置控件的宽高。 - `HorizontalAlignment / VerticalAlignment`:设置水平和垂直对齐方式。 ### 🧩 内容管理: - `Run`:允许在同一 `TextBlock` 中插入多个具有不同样式的内容段。 - `Inlines`:集合类型,存储所有 `Inline` 元素,如 `Run` 或 `Hyperlink`。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值