silverlight系列(Calender、DatePicker、TextBlock、ProgressBar、AutoCompleteBox、PasswordBox、TextBox)

Calender、DatePicker:

Xaml:

  
  
< UserControl xmlns:dataInput ="clr-namespace:System.Windows.Controls;
assembly=System.Windows.Controls.Data.Input"
xmlns:controls ="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
x:Class ="datecontrol.MainPage"
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"
mc:Ignorable
="d" d:DesignWidth ="640" d:DesignHeight ="480" >
< Grid x:Name ="LayoutRoot" HorizontalAlignment ="Left" Width ="Auto" Height ="500"
ShowGridLines ="False" VerticalAlignment ="Top" Margin ="5,5,5,5" >
< Grid.RowDefinitions >
< RowDefinition Height ="200" />
< RowDefinition Height ="55" />
< RowDefinition Height ="35" />
< RowDefinition Height ="35" />
< RowDefinition Height ="35" />
< RowDefinition Height ="Auto" />
</ Grid.RowDefinitions >
< Grid.ColumnDefinitions >
< ColumnDefinition Width ="250" />
< ColumnDefinition />
</ Grid.ColumnDefinitions >
< controls:Calendar x:Name ="cal1" Width ="180" Height ="180" Background ="Ivory"
SelectedDatesChanged ="cal1_SelectedDatesChanged" Grid.Row ="0" >
</ controls:Calendar >
< ListBox x:Name ="lbx1" Width ="250" Grid.Row ="1" Height ="55" ></ ListBox >
< controls:DatePicker x:Name ="dpk1" Width ="180" Height ="25" SelectedDateFormat ="Long"
Background ="AliceBlue" Grid.Row ="2" ></ controls:DatePicker >
< TextBlock x:Name ="tb1" Grid.Row ="3" Width ="180" ></ TextBlock >
</ Grid >
</ UserControl >

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 datecontrol
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
cal1.DisplayDate
= DateTime.Now; // 设置显示的当前日期
cal1.SelectionMode = CalendarSelectionMode.MultipleRange; // 设置日期选择模式、
/*
* SingleRange:只能选择一个日期范围
* SingleDate:只能选择一个日期
* None:不允许选择
* MultipleRange:选择多个非连续日期
*/
cal1.DisplayDateEnd
= DateTime.Now.AddYears( 10 ); // 获取或设置要显示的最后一个日期
cal1.DisplayDateStart = DateTime.Now.AddYears( - 10 ); // 获取或设置要显示的第一个日期
cal1.IsTodayHighlighted = true ; // 今天的日期是否高亮
cal1.DisplayMode = CalendarMode.Month;
/*
* Decade:上方显示以十年为间隔的年格式日期,内容系那是年格式日期
* Year:上方显示年格式日期,内容显示月格式日期
* Month:上方显示月份格式日期,内容显示日格式日期
*/
cal1.BlackoutDates.Add(
new CalendarDateRange( new DateTime( 2010 , 1 , 1 ), new DateTime( 2010 , 1 , 3 )));
// 设置不可选的日期集合
dpk1.CalendarOpened += new RoutedEventHandler(dpk1_CalendarOpened);
dpk1.CalendarClosed
+= new RoutedEventHandler(dpk1_CalendarClosed);
}

private void cal1_SelectedDatesChanged( object sender, SelectionChangedEventArgs e)
{
lbx1.Items.Clear();
foreach (DateTime DT in cal1.SelectedDates)
{
lbx1.Items.Add(DT.ToString(
" yyyy-MM-dd " ));
}
}

void dpk1_CalendarOpened( object sender, RoutedEventArgs e)
{
tb1.Text
= " 开始选择日期 " ;
}

void dpk1_CalendarClosed( object sender, RoutedEventArgs e)
{
tb1.Text
= " 已选择日期 " + dpk1.SelectedDate.Value.ToString( " yyyy-MM-dd " );
}
}
}

运行效果:

TextBlock、ProgressBar、AutoCompleteBox、PasswordBox、TextBox

ProgressBar:

  • IsIndeterminate:true,重复模式;false,基于值填充。
  • Minimum:范围元素的最小值。
  • Maximum:范围元素的最大值。
  • Value:当前显示值。

AutoCompleteBox:

  • MaxDropDownHeight:下拉框最大高度。
  • IsDropDownOpen:指示控件的下拉部分是否已经打开。
  • MinimumPopulateDelay:文本框输入文本后,控件填充下拉项中可能匹配的列表之前的最短延迟时间,毫秒为单位。
  • MinimumPrefixLength:显示可能的匹配项之前需要在文本中输入的最小字符数。
  • SelectedItem:用户键入的文本与ItemSource集合中匹配的项数,若无匹配的则返回Null。

PasswordBox:

  • CaretBrush:呈现指示插入点的竖线的画笔。
  • MaxLength:处理密码的最大长度。
  • Password:当前保留的密码。
  • PasswordChar:掩码字符,默认为"●"。

TextBox:

  • AcceptsReturn:文本框是否允许和显示换行符或回车符。
  • CaretBrush:呈现指示插入点的竖线的画笔。
  • IsReadOnly:是否只可读。
  • MaxLength:允许输入字符的最大长度。
  • VerticalScrollBarVisibility:数值滚动条显示方式。

XAML:

  
  
< UserControl xmlns:input ="clr-namespace:System.Windows.Controls;
assembly=System.Windows.Controls.Input" x:Class ="TextControl.MainPage"
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"
mc:Ignorable
="d" d:DesignWidth ="640" d:DesignHeight ="480" >
< Grid x:Name ="LayoutRoot" HorizontalAlignment ="Left" Width ="Auto" Height ="500"
ShowGridLines ="False" VerticalAlignment ="Top" Margin ="5,5,5,5" >
< Grid.RowDefinitions >
< RowDefinition Height ="35" />
< RowDefinition Height ="35" />
< RowDefinition Height ="35" />
< RowDefinition Height ="35" />
< RowDefinition Height ="60" />
< RowDefinition Height ="35" />
< RowDefinition Height ="Auto" />
</ Grid.RowDefinitions >
< Grid.ColumnDefinitions >
< ColumnDefinition Width ="150" />
< ColumnDefinition />
</ Grid.ColumnDefinitions >
< TextBlock x:Name ="tbl1" FontSize ="12" Text ="我是文本框" Grid.Row ="0" ></ TextBlock >
< ProgressBar x:Name ="pb1" IsIndeterminate ="True" Width ="150" Height ="25"
Background ="AliceBlue" Grid.Row ="1" Grid.Column ="0" Minimum ="0" Maximum ="200" ></ ProgressBar >
< ProgressBar x:Name ="pb2" IsIndeterminate ="False" Width ="150" Height ="25"
Background ="AliceBlue" Grid.Row ="1" Grid.Column ="1" Minimum ="0" Maximum ="200"
Value ="50" Margin ="5,5,5,5" ></ ProgressBar >
<!--
IsIndeterminate:true,重复模式;false,基于值填充.
Minimum:范围元素的最小值
Maximum:范围元素的最大值
Value:当前显示值
-->
< input:AutoCompleteBox x:Name ="acb1" Width ="150" Height ="25" Grid.Row ="2" MaxDropDownHeight ="50"
MinimumPopulateDelay
="2" MinimumPrefixLength ="2" ></ input:AutoCompleteBox >
<!--
MaxDropDownHeight:下拉框最大高度
IsDropDownOpen:指示控件的下拉部分是否已经打开
MinimumPopulateDelay:文本框输入文本后,控件填充下拉项中可能匹配的列表之前的最短延迟时间,毫秒为单位
MinimumPrefixLength:显示可能的匹配项之前需要在文本中输入的最小字符数
SelectedItem:用户键入的文本与ItemSource集合中匹配的项数,若无匹配的则返回Null
-->
< PasswordBox x:Name ="pwb1" Width ="150" Height ="25" Grid.Row ="3"
Background ="AntiqueWhite" CaretBrush ="Red" MaxLength ="8" Password ="keysky"
PasswordChar ="$" PasswordChanged ="pwb1_PasswordChanged" ></ PasswordBox >
<!--
CaretBrush:呈现指示插入点的竖线的画笔
MaxLength:处理密码的最大长度
Password:当前保留的密码
PasswordChar:掩码字符,默认为"●"
-->
< TextBlock x:Name ="tbl2" FontSize ="12" Grid.Row ="3"
Grid.Column ="1" Margin ="5,5,5,5" ></ TextBlock >
< TextBox x:Name ="tb1" FontSize ="12" Grid.Row ="4" Margin ="5,5,5,5" AcceptsReturn ="True"
CaretBrush ="Green" Text ="我是文本框" VerticalScrollBarVisibility ="Auto"
TextChanged ="tb1_TextChanged" Height ="50" ></ TextBox > 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 TextControl
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
List
< string > cities = new List < string > ();
cities.Add(
" BeiJing " );
cities.Add(
" ShangHai " );
cities.Add(
" TianJin " );
cities.Add(
" XiAn " );
cities.Add(
" QingDao " );
acb1.ItemsSource
= cities;
}

private void pwb1_PasswordChanged( object sender, RoutedEventArgs e)
{
tbl2.Text
= pwb1.Password;
}

private void tb1_TextChanged( object sender, TextChangedEventArgs e)
{
MessageBox.Show(
" 我的内容改变了,现在是: " + tb1.Text);
}
}
}

运行效果:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值