吴佳鑫的个人专栏

当日事当日毕,没有任何借口

导航

silverlight控件学习笔记二

TextBlock.xaml

<UserControl x:Class="Silverlight20.Control.TextBlock"
xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel HorizontalAlignment="Left">

<!--
Text - TextBlock上显示的值
-->
<TextBlock Text="TextBlock" />

<!--
Foreground - 字体颜色
-->
<TextBlock Text="红色的TextBlock" Foreground="Red" />

<!--
要以XAML的方式直接显示引号等特殊字请使用相应的HTML编码
-->
<TextBlock Text="带引号的&quot;TextBlock&quot;" />

<!--
FontFamily - 字体
FontSize - 字体大小
FontWeight - 字形粗细度 [System.Windows.FontWeights枚举]
FontStyle - 字形斜体否 [System.Windows.FontStyles枚举]
TextDecorations - 字体下划线 [System.Windows.TextDecorations枚举]
FontStretch - 字体间距 [System.Windows.FontStretches枚举]
-->
<TextBlock Text="常用属性TextBlock" FontFamily="宋体" FontSize="36" FontWeight="Bold" FontStyle="Italic" TextDecorations="Underline" FontStretch="Normal" />

<!--
TextAlignment - 文字排列 [System.Windows.TextAlignment枚举]
Run - 文本内容
LineBreak - 换行符
LineHeight - 每行行高
TextWrapping - 文本限制(超过限制是否换行)
NoWrap - 永不换行
Wrap - 超过限制则换行
LineStackingStrategy - 控制行高的策略
MaxHeight - TextBlock内每行的行高 以LineHeight值 和 每行自身所设置的行高值 间的最大值为准
BlockLineHeight - TextBlock内每行的行高 以LineHeight值为准
-->
<TextBlock VerticalAlignment="Center" TextAlignment="Center" LineHeight="10" LineStackingStrategy="MaxHeight" Width="200" TextWrapping="NoWrap">
<Run FontSize="20" Foreground="Maroon" Text="MaroonMaroonMaroonMaroon" />
<LineBreak/>
<Run Foreground="Teal" Text="Teal" />
<LineBreak/>
<Run FontSize="30" Foreground="SteelBlue" Text="SteelBlue" />
</TextBlock>


<TextBlock VerticalAlignment="Center" TextAlignment="Center" LineHeight="10" LineStackingStrategy="BlockLineHeight" Width="200" TextWrapping="Wrap">
<Run FontSize="20" Foreground="Red" Text="RedRedRedRedRedRedRedRedRed" />
<LineBreak/>
<Run Foreground="Green" Text="Green" />
<LineBreak/>
<Run FontSize="30" Foreground="Blue" Text="Blue" />
</TextBlock>

</StackPanel>
</UserControl>

 

TextBox.xaml

<UserControl x:Class="Silverlight20.Control.TextBox"
xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel HorizontalAlignment="Left" Width="200">

<!--
Text - TextBox内显示的值
BorderThickness - 边框的宽度(像素值:上下左右;左右,上下;左,上,右,下)
BorderBrush - 边框的颜色
-->
<TextBox Text="红色框绿色底蓝色字(真难看)" BorderBrush="Red" BorderThickness="1,5" Background="Green" Foreground="Blue" Margin="6" />

<!--
IsReadOnly - 是否只读
-->
<TextBox Text="只读TextBox" IsReadOnly="True" Margin="6" />

<!--
AcceptsReturn - 是否允许输入回车
HorizontalScrollBarVisibility - 水平滚动条的显示状态
VerticalScrollBarVisibility - 垂直滚动条的显示状态
Auto - 自动根据TextBox控件的宽和高,以及其内容的宽和高,来决定是否显示滚动条
Disabled - 不显示,但是可以通过键盘或鼠标在显示内容中的移动或拖动操作,来看到被遮挡的内容
Hidden - 不显示,而且无法看到被遮挡的内容
Visible - 显示滚动条
-->
<TextBox Height="50" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" Margin="6"
Text
="多行文本框1 多行文本框2 多行文本框3 多行文本框4 多行文本框5 多行文本框6" />

<!--
SelectionChanged - 选中的文本内容发生变化时所触发的事件
-->
<TextBox Height="50" AcceptsReturn="False" Margin="5" SelectionChanged="TextBox_SelectionChanged"
Text
="相应选中事件多行文本框1 多行文本框2 多行文本框3" />

<TextBlock Margin="5">
<Run>选中的文本为:</Run>
<LineBreak />
<Run x:Name="lblMsg"></Run>
</TextBlock>

</StackPanel>
</UserControl>

 

TextBox.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Silverlight20.Control
{
public partial class TextBox : UserControl
{
public TextBox()
{
InitializeComponent();
}

private void TextBox_SelectionChanged(object sender, RoutedEventArgs e)
{
lblMsg.Text = ((System.Windows.Controls.TextBox)sender).SelectedText;
}
}
}

 




 

posted on 2011-09-22 14:20  _eagle  阅读(385)  评论(0编辑  收藏  举报