silverlight控件学习笔记一

 

Calendar.xaml

<!--
Calendar控件的命名空间和其他控件一样,都是在System.Windows.Controls下
但是其是在System.Windows.Controls.dll程序集中定义的
所以要引入相应的xml命名空间
-->
<UserControl x:Class="Silverlight20.Control.Calendar"
xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:basics
="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls">
<StackPanel HorizontalAlignment="Left">
<TextBox x:Name="txtMsg" Margin="5" />

<!--
SelectedDatesChanged - 选中日期后所触发的事件
DisplayDateEnd - 此日期之后的日期不予显示
DisplayDateStart - 此日期之前的日期不予显示
FirstDayOfWeek - 控件所显示的每星期的第一天为星期几 [System.DayOfWeek枚举]
DisplayMode - 控件的显示模式 [System.Windows.Controls.DisplayMode枚举]
DisplayMode.Month - 标题显示年月,内容显示日期。默认值
DisplayMode.Year - 标题显示年,内容显示月
DisplayMode.Decade - 标题显示一个十年的区间,内容显示年
IsTodayHighlighted - 是否高亮显示今天的日期
-->
<basics:Calendar x:Name="calendar" Margin="5" FirstDayOfWeek="Monday"
SelectedDatesChanged
="calendar_SelectedDatesChanged">
</basics:Calendar>

<StackPanel Orientation="Horizontal">

<CheckBox Content="禁止选择今天以前的日期" Margin="5"
Checked
="CheckBox_Checked" Unchecked="CheckBox_Unchecked" />

<RadioButton GroupName="selectionMode" x:Name="SingleDate" Content="可选单一日期" Margin="5"
Checked
="selectionMode_Changed" />

<RadioButton GroupName="selectionMode" x:Name="None" Content="不可选日期" Margin="5"
Checked
="selectionMode_Changed" />

<RadioButton GroupName="selectionMode" x:Name="SingleRange" Content="可选连续日期(shift)" Margin="5"
Checked
="selectionMode_Changed" />

<RadioButton GroupName="selectionMode" x:Name="MultipleRange" Content="可选多个日期(ctrl)" Margin="5"
Checked
="selectionMode_Changed" />

</StackPanel>

</StackPanel>
</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 Silverlight20.Control
{
public partial class Calendar : UserControl
{
public Calendar()
{
InitializeComponent();
}

private void calendar_SelectedDatesChanged(object sender, SelectionChangedEventArgs e)
{
// Calendar.SelectedDate - 选中的日期
// Calendar.SelectedDates - 选中的多个日期集合

this.txtMsg.Text = "";
foreach (DateTime dt in calendar.SelectedDates)
{
this.txtMsg.Text += dt.ToString("yyyy-MM-dd");
this.txtMsg.Text += " ";
}
}

private void CheckBox_Checked(object sender, RoutedEventArgs e)
{
if (this.calendar.SelectedDate != null && this.calendar.SelectedDate < DateTime.Now.Date)
this.calendar.SelectedDate = DateTime.Now;

// Calendar.BlackoutDates - 不允许选择的日期集合
// Calendar.BlackoutDates.AddDatesInPast() - 禁止选择今天之前的日期
this.calendar.BlackoutDates.AddDatesInPast();
}

private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
{
// Calendar.BlackoutDates.Clear() - 清除 不允许选择的日期集合 的设置
this.calendar.BlackoutDates.Clear();
}

private void selectionMode_Changed(object sender, RoutedEventArgs e)
{
// CalendarSelectionMode.None - 禁止选择日期
// CalendarSelectionMode.SingleRange - 可以选择多个日期,连续日期(Shift键配合)
// CalendarSelectionMode.MultipleRange - 可以选择多个日期,任意日期(Ctrl键配合)
// CalendarSelectionMode.SingleDate - 只能选择一个日期
switch (((System.Windows.Controls.RadioButton)sender).Name)
{
case "None":
this.calendar.SelectionMode = CalendarSelectionMode.None;
break;
case "SingleRange":
this.calendar.SelectionMode = CalendarSelectionMode.SingleRange;
break;
case "MultipleRange":
this.calendar.SelectionMode = CalendarSelectionMode.MultipleRange;
break;
default:
this.calendar.SelectionMode = CalendarSelectionMode.SingleDate;
break;
}
}
}
}

 

 

Image.xaml

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

<!--
Source - 程序目录下的图片文件地址
-->
<Image Source="/Logo.jpg" Margin="5" Width="100" />

<!--
Source - 程序集内的图片文件地址 [/程序集名;component/图片路径]
-->
<Image Source="/Silverlight20;component/Images/Logo.jpg" Margin="5" Width="200" />

<!--
Source - 互联网的图片文件地址
-->
<Image Source="http://silverlight.net/Themes/silverlight/images/logo.jpg" Margin="5" Width="100" />

<!--
Source - 后台方式设置Image的Source
-->
<Image x:Name="img" Margin="5" Width="100" />
<Image x:Name="img2" Margin="5" Width="100" />

</StackPanel>
</UserControl>

 

Image.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;

using System.Windows.Media.Imaging;
using System.Windows.Resources;

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

// 后台方式设置Image的Source
img.Source = new BitmapImage(new Uri("/Silverlight20;component/Images/Logo.jpg", UriKind.Relative));

StreamResourceInfo sri = Application.GetResourceStream(
new Uri("/Silverlight20;component/Images/Logo.jpg", UriKind.Relative));
BitmapImage imageSource = new BitmapImage();
imageSource.SetSource(sri.Stream);
img2.Source = imageSource;
}
}
}

 

ProgressBar.Xaml

<UserControl
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"
x:Class
="SilverlightApplication50.progressBar"
d:DesignWidth
="640" d:DesignHeight="480">

<Grid x:Name="LayoutRoot">
<ProgressBar x:Name="bar1" Height="30" VerticalAlignment="Top" Margin="174,110,217,0"/>
<ProgressBar x:Name="bar2" Height="30" VerticalAlignment="Top" Margin="174,175,217,0"/>
</Grid>
</UserControl>

 

 

ProgressBar.cs

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace SilverlightApplication50
{
public partial class progressBar : UserControl
{
Storyboard loop = new Storyboard();
int count = 0;
public progressBar()
{
// 为初始化变量所必需
InitializeComponent();
initBar();//方法一
//initBar2();//方法二
}

//利用定时器每隔一段时间执行
private void initBar()
{
//使用DispatcherTimer之前,要引用using System.Windows.Threading;命名空间
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = new TimeSpan(0,0,1);
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}

//利用动画的时间间隔
private void initBar2()
{
loop.Duration = TimeSpan.FromMilliseconds(10d);
loop.Completed += new EventHandler(loop_Completed);
loop.Begin();
}

void timer_Tick(object sender, EventArgs e)
{
bar2.Value = count;

if (count > 100)
{
count = 0;
}
else
{
count++;
}
}

void loop_Completed(object sender, EventArgs e)
{
bar2.Value = count;

if (count>100)
{
count = 0;
}
else
{
count++;
}
loop.Begin();

}
}
}

 

 

Slider.xaml

 

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

<!--
Minimum - Slider控件的最小值。参见基类System.Windows.Controls.Primitives.RangeBase
Maximum - Slider控件的最大值。参见基类System.Windows.Controls.Primitives.RangeBase
Value - Slider控件的值。参见基类System.Windows.Controls.Primitives.RangeBase
SmallChange - 按上/下/左/右键的时候,Slider 控件的 Value 值的变化跨度。参见 Slider 的基类 System.Windows.Controls.Primitives.RangeBase
LargeChange - 鼠标在 Slider 上单击的时候,Slider 控件的 Value 值的变化跨度。参见 Slider 的基类 System.Windows.Controls.Primitives.RangeBase
ValueChanged - Slider控件的值发生变化时所触发的事件
Orientation - 控件的放置方向
Horizontal - 水平放置
Vertical - 垂直放置
IsDirectionReversed - 滑块的初始位置
True - 上到下 或者 右到左
False - 下到上 或者 左到右
-->
<Slider Height="400" HorizontalAlignment="Left" Orientation="Vertical" IsDirectionReversed="True" Minimum="0" Maximum="50" SmallChange="5" ValueChanged="Slider_ValueChanged" />

<TextBlock x:Name="lblMsg" HorizontalAlignment="Left" />

</StackPanel>
</UserControl>

 

Slider.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 Slider : UserControl
{
public Slider()
{
InitializeComponent();
}

private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
// RoutedPropertyChangedEventArgs<double>.OldValue - Slider控件的原值
// RoutedPropertyChangedEventArgs<double>.NewValue - Slider控件的新值

lblMsg.Text = string.Format("原值:{0}\r\n新值:{1}", e.OldValue.ToString(), e.NewValue.ToString());
}
}
}

 

TabControl.xaml

<UserControl x:Class="Silverlight20.Control.TabControl"
xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:basics
="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls">
<StackPanel HorizontalAlignment="Left">

<!--
SelectedIndex - 被选中的 TabItem 索引
SelectedItem - 被选中的 TabItem 对象
-->
<basics:TabControl Width="400" Height="400" SelectedIndex="1">

<basics:TabItem Header="Tab1">
<TextBlock Text="Tab1 Content" />
</basics:TabItem>

<!--
TabItem.Header - TabItem 的标题
TabItem.Content - TabItem 的内容
-->
<basics:TabItem>
<basics:TabItem.Header>
<TextBlock Text="Tab2"/>
</basics:TabItem.Header>
<basics:TabItem.Content>
<TextBlock Text="Tab2 Content" />
</basics:TabItem.Content>
</basics:TabItem>

<basics:TabItem>
<basics:TabItem.Header>
<Image Source="/Silverlight20;component/Images/Logo.jpg" Height="20" />
</basics:TabItem.Header>
<TextBlock Text="Tab3 Content"></TextBlock>
</basics:TabItem>

<basics:TabItem>
<basics:TabItem.Header>
<Grid Width="100">
<Image Source="/Silverlight20;component/Images/Logo.jpg" Height="20" HorizontalAlignment="Center" />
<TextBlock Text="Tab4" HorizontalAlignment="Center" />
</Grid>
</basics:TabItem.Header>
<TextBlock Text="Tab4 Content"></TextBlock>
</basics:TabItem>

</basics:TabControl>

</StackPanel>
</UserControl>

 

 

摘自:http://www.cnblogs.com/webabcd/archive/2007/02/24/655035.html

 



 






 

转载于:https://www.cnblogs.com/eagle1986/archive/2011/09/22/2184843.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值