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">


<TextBlock Text="TextBlock" />


<TextBlock Text="红色的TextBlock" Foreground="Red" />


<TextBlock Text="带引号的"TextBlock"" />


<TextBlock Text="常用属性TextBlock" FontFamily="宋体" FontSize="36" FontWeight="Bold" FontStyle="Italic" TextDecorations="Underline" FontStretch="Normal" />


<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">


<TextBox Text="红色框绿色底蓝色字(真难看)" BorderBrush="Red" BorderThickness="1,5" Background="Green" Foreground="Blue" Margin="6" />


<TextBox Text="只读TextBox" IsReadOnly="True" Margin="6" />


<TextBox Height="50" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" Margin="6"
Text
="多行文本框1 多行文本框2 多行文本框3 多行文本框4 多行文本框5 多行文本框6" />


<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;
}
}
}

 




 

你可能感兴趣的:(silverlight控件学习笔记二)