注:在这里感谢作者:webabcd,在学习Silverlight中给了很好的参考(大部分源码来自于webabcd)。http://www.cnblogs.com/webabcd
1、border.xaml
<UserControl x:Class="SilverlightBasic.Control.borderTest"
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:DesignHeight="300" d:DesignWIDth="400">
<StackPanel WIDth="400" Height="300" OrIEntation="Horizontal">
<!--
borderThickness:边框的宽度[uniform];[leftright,topbottom];[left,top,right,bottom]
borderBrush:边框的颜色
CornerRadius:边框角的半径
-->
<border borderBrush="#FF0000" borderThickness="1,3,5,7" CornerRadius="5"
WIDth="120" Height="200" margin="5">
<TextBlock Text="红色border" tooltipService.tooltip="红色border" TextAlignment="Center"/>
</border>
<border borderThickness="8" CornerRadius="10" WIDth="120" Height="200" margin="5">
<TextBlock Text="红色border1" tooltipService.tooltip="红色border" TextAlignment="Center"/>
<border.borderBrush>
<!-- ***ImageBrush:图像画笔***
ImageSource - 图片地址
Stretch属性 - 拉伸值 [System.windows.Media.Stretch 枚举]
AlignmentX - 水平方向的对齐方式。Center(默认值),left,Right
AlignmentY - 垂直方向的对齐方式。Center(默认值),top,Bottom
-->
<ImageBrush ImageSource="/SilverlightBasic;component/Image/border.jpg"/>
</border.borderBrush>
</border>
</StackPanel>
</UserControl>
2、button.xaml
<UserControl x:Class="SilverlightBasic.Control.buttonTest"
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:DesignHeight="300" d:DesignWIDth="400">
<StackPanel WIDth="400" OrIEntation="Horizontal">
<!--
Content:按钮上显示的内容
Click:按钮的单击事件
Cursor:鼠标移动到按钮上面时,鼠标指针的样式
padding:容器内的内容与容器边缘的填充距离[uniform];[leftright,topbottom];
[left,bottom]
-->
<button Tag="我是button" Content="button" Cursor="Eraser" padding="5"
WIDth="70" Height="35" margin="5"/>
<!-- IsEnabled:按钮是否有效 -->
<button Tag="无效button" Content="无效button" IsEnabled="False"
WIDth="70" Height="35" margin="5" />
<!--
button.Content - 按钮上显示的内容
ClickMode - 触发单击事件的类型 [System.windows.Controls.ClickMode枚举]
1、以反斜杠开头的图片(Source="/images/Dingoslogo.png")需要放在ClIEntBin目录下的相应文件夹中
2、不以反斜杠开头的图片(Source="images/Dingoslogo.png")应该放在Silverlight 项目的目录下的相应文件夹里
-->
<button Tag="图片button" ClickMode="Release" Click="button_Click" margin="5" WIDth="70" Height="35">
<button.Content>
<Image Source="/SilverlightBasic;component/Image/01.jpg" Stretch="UniformToFill" />
</button.Content>
</button>
</StackPanel>
</UserControl>
button.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.browser;
namespace SilverlightBasic.Control
{
public partial class buttonTest : UserControl
{
public buttontest()
{
InitializeComponent();
}
/**
* 页面Alert
*/
private voID button_Click(object sender,RoutedEventArgs e){
HTMLWindow HTML = HTMLPage.Window;
HTML.Alert(((System.windows.Controls.button)sender).Tag.ToString() + "被单击了");
}
}
}
3、 Calendar.xaml
<UserControl x:Class="SilverlightBasic.Control.DateControl"
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:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
mc:Ignorable="d"
d:DesignHeight="400" d:DesignWIDth="600">
<!--
注意:在presentation/sdk命名空间下
DateControl包括两个控件:DatePicker和Calendar
-->
<StackPanel margin="0,100,0">
<sdk:DatePicker name="dplong" SelectedDateFormat="Long" WIDth="200"/>
<sdk:DatePicker name="dpShort" SelectedDateFormat="Short" WIDth="200"/>
<StackPanel OrIEntation="Horizontal" margin="10" HorizontalAlignment="Center">
<!--
SelectedDatesChanged - 选中日期后所触发的事件
displayDateEnd - 此日期之后的日期不予显示
displayDateStart - 此日期之前的日期不予显示
FirstDayOfWeek - 控件所显示的每星期的第一天为星期几 [System.DayOfWeek枚举]
displayMode - 控件的显示模式 [System.windows.Controls.displayMode枚举]
IsTodayHighlighted - 是否高亮显示今天的日期
-->
<StackPanel margin="2">
<TextBlock Text="displayMode=Decade" padding="5"/>
<sdk:Calendar displayMode="Decade"/>
</StackPanel>
<StackPanel margin="2">
<TextBlock Text="displayMode=Month" padding="5"/>
<sdk:Calendar displayMode="Month" IsTodayHighlighted="True" FirstDayOfWeek="Monday"/>
</StackPanel>
<StackPanel margin="2">
<TextBlock Text="displayMode=Year" padding="5"/>
<sdk:Calendar displayMode="Year"/>
</StackPanel>
</StackPanel>
</StackPanel>
</UserControl>
4、Canvas.xaml
<UserControl x:Class="SilverlightBasic.Control.CanvasTest"
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:DesignHeight="300" d:DesignWIDth="400">
<!-- Canvas:绝对布局模式
Canvas.left:与上一层 Canvas 的 Y轴 间的距离,左上角为原点
Canvas.top:与上一层 Canvas 的 X轴 间的距离,左上角为原点
-->
<Canvas Background="#FF00FF" WIDth="100" Height="100">
<Canvas Background="Green" WIDth="100" Height="100" Canvas.left="100" Canvas.top="100">
<TextBlock Text="TextBlock" Canvas.top="20" />
</Canvas>
</Canvas>
</UserControl>
5、CheckBox.xaml
<UserControl x:Class="SilverlightBasic.Control.CheckBoxTest"
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:DesignHeight="300" d:DesignWIDth="400">
<StackPanel>
<!-- IsChecked - 是否被选中 -->
<CheckBox name="chk1" Content="我是CheckBox" IsChecked="false" margin="5"/>
<!--
IsThreeState:是否是有3个状态的CheckBox
false:通常的两状态。默认值
true:有3个状态:true,false,null。
也就是说 CheckBox.IsChecked是bool?类型
-->
<CheckBox name="chk2" Content="红色的三状态CheckBox" Background="Red"
IsThreeState="True" margin="5"/>
<!-- IsEnabled:CheckBox是否有效 -->
<CheckBox name="chk3" Content="无效的CheckBox" IsEnabled="False" margin="5"/>
<!--
CheckBox.Content:CheckBox所对应的内容
Checked:被选中后所触发的事件
Unchecked:被取消选中后所触发的事件
Click: 被单击后所触发的事件
-->
<CheckBox name="chk4" Checked="button_Click" margin="5">
<CheckBox.Content>
<Image Source="/SilverlightBasic;component/Image/01.jpg" WIDth="100"/>
</CheckBox.Content>
</CheckBox>
<button Content="各个CheckBox的选中状态" WIDth="200" HorizontalAlignment="left"
Click="button_Click" margin="5"/>
</StackPanel>
</UserControl>
CheckBox.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.browser;//引入HTMLPage HTMLWindow
namespace SilverlightBasic.Control
{
public partial class CheckBoxTest : UserControl
{
public CheckBoxtest()
{
InitializeComponent();
}
private voID button_Click(object sender,RoutedEventArgs e) {
HTMLWindow HTML = HTMLPage.Window;
HTML.Alert(string.Format("chk1: {0}\r\nchk2: {1}\r\nchk3: {2}\r\nchk4: {3}",
chk1.IsChecked,chk2.IsChecked,chk3.IsChecked,chk4.IsChecked));
}
}
}
6、ComboBox.xaml
<UserControl x:Class="SilverlightBasic.Control.ComboBoxTest"
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:DesignHeight="300" d:DesignWIDth="400">
<StackPanel>
<ComboBox name="cbo" WIDth="200" margin="5">
<ComboBoxItem Content="ComboBoxItem1"/>
<ComboBoxItem Content="ComboBoxItem2"/>
<ComboBoxItem Content="ComboBoxItem3"/>
</ComboBox>
<ComboBox name="cbo2" displayMemberPath="name" MaxDropDownHeight="100"
WIDth="200" margin="5"/>
</StackPanel>
</UserControl>
ComboBox.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 SilverlightBasic.DataBing;//SourceDataModel SourceData
namespace SilverlightBasic.Control
{
public partial class ComboBoxTest : UserControl
{
public ComboBoxtest()
{
InitializeComponent();
BingData();
}
private voID BingData() {
SourceData source = new DataBing.sourceData();
cbo2.ItemsSource = source.GetData();
}
}
}
-------------------------------------------------------------------------------------------------------------------------------------------------
总结以上是内存溢出为你收集整理的Study Silverlight《控件之Border, Button, Calendar, Canvas, CheckBox, ComboBox 》全部内容,希望文章能够帮你解决Study Silverlight《控件之Border, Button, Calendar, Canvas, CheckBox, ComboBox 》所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)