稳扎稳打Silverlight(5) - 2.0控件之ListBox, MediaElement, MultiScaleImage, PasswordBox
[源码下载]
作者:webabcd
介绍
Silverlight 2.0 控件一览:ListBox, MediaElement, MultiScaleImage, PasswordBox, ProgressBar, RadioButton
在线DEMO
http://webabcd.blog.51cto.com/1787395/342779
示例
1、ListBox.xaml
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel HorizontalAlignment="Left">
<!--
SelectionChanged - ListBox中某个对象被选中后所触发的事件
-->
<ListBox Margin="5" Width="200" Height="100" SelectionChanged="ListBox_SelectionChanged">
<ListBoxItem Content="ListBoxItem01" />
<ListBoxItem Content="ListBoxItem02" />
<ListBoxItem Content="ListBoxItem03" />
<ListBoxItem Content="ListBoxItem04" />
<ListBoxItem Content="ListBoxItem05" />
<ListBoxItem Content="ListBoxItem06" />
<ListBoxItem Content="ListBoxItem07" />
<ListBoxItem Content="ListBoxItem08" />
<ListBoxItem Content="ListBoxItem09" />
<ListBoxItem Content="ListBoxItem10" />
</ListBox>
<!--
ListBox中可以包含任何对象
-->
<ListBox Margin="5" Width="200">
<TextBlock Text="TextBlock" />
<TextBox Text="TextBox" />
<Button Content="Button" />
</ListBox>
</StackPanel>
</UserControl>
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 Silverlight20.Control
{
public partial class ListBox : UserControl
{
public ListBox()
{
InitializeComponent();
}
private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// ListBox.SelectedItem - ListBox中被选中的对象
var lst = sender as System.Windows.Controls.ListBox;
MessageBox.Show(
((System.Windows.Controls.ListBoxItem)lst.SelectedItem).Content + " 被单击了",
"提示",
MessageBoxButton.OK);
}
}
}
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel HorizontalAlignment="Center">
<!--
Source - 视频路径
AutoPlay - 是否自动播放
-->
<MediaElement x:Name="mediaElement" Height="250" AutoPlay="False"
Source="/Silverlight20;component/Video/Demo.wmv" />
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<ToggleButton x:Name="play" Content="播放" Margin="5" Click="play_Click" />
<ToggleButton x:Name="mute" Content="静音" Margin="5" Click="mute_Click" />
</StackPanel>
</StackPanel>
</UserControl>
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 MediaElement : UserControl
{
public MediaElement()
{
InitializeComponent();
}
void play_Click(object sender, RoutedEventArgs e)
{
var tb = sender as System.Windows.Controls.Primitives.ToggleButton;
if (tb.IsChecked == true)
{
tb.Content = "暂停";
// MediaElement.Play() - 播放视频
this.mediaElement.Play();
}
else
{
tb.Content = "播放";
// MediaElement.Pause() - 暂停视频
// MediaElement.Stop() - 停止视频
this.mediaElement.Pause();
}
}
void mute_Click(object sender, RoutedEventArgs e)
{
var tb = sender as System.Windows.Controls.Primitives.ToggleButton;
if (tb.IsChecked == true)
{
tb.Content = "有声";
// MediaElement.IsMuted - 是否静音
// MediaElement.Volume - 声音大小(0 - 1)
this.mediaElement.IsMuted = true;
}
else
{
tb.Content = "静音";
this.mediaElement.IsMuted = false;
}
}
}
}
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel HorizontalAlignment="Left">
<MultiScaleImage x:Name="msi" Width="400" Height="300"></MultiScaleImage>
</StackPanel>
</UserControl>
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 MultiScaleImage : UserControl
{
//
// Based on prior work done by Lutz Gerhard, Peter Blois, and Scott Hanselman
//
Point lastMousePos = new Point();
double _zoom = 1;
bool mouseButtonPressed = false;
bool mouseIsDragging = false;
Point dragOffset;
Point currentPosition;
public double ZoomFactor
{
get { return _zoom; }
set { _zoom = value; }
}
public MultiScaleImage()
{
InitializeComponent();
//
// We are setting the source here, but you should be able to set the Source property via
//
this.msi.Source = new DeepZoomImageTileSource(new Uri("/DeepZoomImages/dzc_output.xml", UriKind.Relative));
//
// Firing an event when the MultiScaleImage is Loaded
//
this.msi.Loaded += new RoutedEventHandler(msi_Loaded);
//
// Firing an event when all of the images have been Loaded
//
this.msi.ImageOpenSucceeded += new RoutedEventHandler(msi_ImageOpenSucceeded);
//
// Handling all of the mouse and keyboard functionality
//
this.MouseMove += delegate(object sender, MouseEventArgs e)
{
if (mouseButtonPressed)
{
mouseIsDragging = true;
}
this.lastMousePos = e.GetPosition(this.msi);
};
this.MouseLeftButtonDown += delegate(object sender, MouseButtonEventArgs e)
{
mouseButtonPressed = true;
mouseIsDragging = false;
dragOffset = e.GetPosition(this);
currentPosition = msi.ViewportOrigin;
};
this.msi.MouseLeave += delegate(object sender, MouseEventArgs e)
{
mouseIsDragging = false;
};
this.MouseLeftButtonUp += delegate(object sender, MouseButtonEventArgs e)
{
mouseButtonPressed = false;
if (mouseIsDragging == false)
{
bool shiftDown = (Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift;
ZoomFactor = 2.0;
if (shiftDown) ZoomFactor = 0.5;
Zoom(ZoomFactor, this.lastMousePos);
}
mouseIsDragging = false;
};
this.MouseMove += delegate(object sender, MouseEventArgs e)
{
if (mouseIsDragging)
{
Point newOrigin = new Point();
newOrigin.X = currentPosition.X - (((e.GetPosition(msi).X - dragOffset.X) / msi.ActualWidth) * msi.ViewportWidth);
newOrigin.Y = currentPosition.Y - (((e.GetPosition(msi).Y - dragOffset.Y) / msi.ActualHeight) * msi.ViewportWidth);
msi.ViewportOrigin = newOrigin;
}
};
new MouseWheelHelper(this).Moved += delegate(object sender, MouseWheelEventArgs e)
{
e.Handled = true;
if (e.Delta > 0)
ZoomFactor = 1.2;
else
ZoomFactor = .80;
Zoom(ZoomFactor, this.lastMousePos);
};
}
void msi_ImageOpenSucceeded(object sender, RoutedEventArgs e)
{
//If collection, this gets you a list of all of the MultiScaleSubImages
//
//foreach (MultiScaleSubImage subImage in msi.SubImages)
//{
// // Do something
//}
}
void msi_Loaded(object sender, RoutedEventArgs e)
{
// Hook up any events you want when the image has successfully been opened
}
public void Zoom(double zoom, Point pointToZoom)
{
Point logicalPoint = this.msi.ElementToLogicalPoint(pointToZoom);
this.msi.ZoomAboutLogicalPoint(zoom, logicalPoint.X, logicalPoint.Y);
}
/*
* Sample event handlerrs tied to the Click of event of various buttons for
* showing all images, zooming in, and zooming out!
*
private void ShowAllClick(object sender, RoutedEventArgs e)
{
this.msi.ViewportOrigin = new Point(0, 0);
this.msi.ViewportWidth = 1;
ZoomFactor = 1;
}
private void zoomInClick(object sender, RoutedEventArgs e)
{
Zoom(1.2, new Point(this.ActualWidth / 2, this.ActualHeight / 2));
}
private void zoomOutClick(object sender, RoutedEventArgs e)
{
Zoom(.8, new Point(this.ActualWidth / 2, this.ActualHeight / 2));
}
* */
}
}
[源码下载]
稳扎稳打Silverlight(5) - 2.0控件之ListBox, MediaElement, MultiScaleImage, PasswordBox相关推荐
- 稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager
[索引页] [源码下载] 稳扎稳打Silverlight(33) - 3.0控件之AutoCompleteBox, DataPager 作者:webabcd 介绍 Silverlight 3.0 控件 ...
- 稳扎稳打Silverlight(18) - 2.0视频之详解MediaElement, 开发一个简易版的全功能播放器...
[索引页] [×××] 稳扎稳打Silverlight(18) - 2.0视频之详解MediaElement, 开发一个简易版的全功能播放器 作者:webabcd 介绍 Silverlight 2.0 ...
- silverlight体验之三:简单控件堆成个Login
silverlight体验之三:简单控件堆成个Login 快过年了,回家心情急切呀.今天,明天,后天一上午.就可以回家啦,高兴,再记点小东西吧. 好像web项目都是从登陆开始的吧,这个也一样. 1. ...
- DateChooser控件发布ASP.NET 2.0新版(我的ASP.NET 2.0控件开发书的第二个阶段项目)[请大家一定注意版本的更新,下载最新版]...
已更新实用版:DateChooser ASP.NET 2.0版 之实用版 请大家一定注意版本的更新,下载最新版 DateChooser的ASP.NET 1.x版在二年前就发布了,二年以来,ASP.NE ...
- 微软 microsoft calendar control 11.0 控件下载
微软 microsoft calendar control 11.0 控件下载 https://files.cnblogs.com/files/mqingqing123/csccal2.rar
- 稳扎稳打Silverlight(13) - 2.0交互之鼠标事件和键盘事件
[索引页] [×××] 稳扎稳打Silverlight(13) - 2.0交互之鼠标事件和键盘事件 作者:webabcd 介绍 Silverlight 2.0 人机交互:响应用户的鼠标操作和键盘操作 ...
- 稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 绑定数据到ListBox
[索引页] [源码下载] 稳扎稳打Silverlight(17) - 2.0数据之详解DataGrid, 详解ListBox 作者:webabcd 介绍 Silverlight 2.0 详解DataG ...
- 稳扎稳打Silverlight(8) - 2.0图形之基类System.Windows.Shapes.Shape
[索引页] [×××] 稳扎稳打Silverlight(8) - 2.0图形之基类System.Windows.Shapes.Shape 作者:webabcd 介绍 Silverlight 2.0 图 ...
- 稳扎稳打Silverlight(25) - 2.0线程之Thread, Timer, BackgroundWorker, ThreadPool
[索引页] [源码下载] 稳扎稳打Silverlight(25) - 2.0线程之Thread, Timer, BackgroundWorker, ThreadPool 作者:webabcd 介绍 S ...
- 海康摄像机web3.0控件
@海康摄像机web3.0控件TOC # 海康摄像机web3.0控件 https://blog.csdn.net/weixin_41196185/article/details/81067360
最新文章
- C/C++变量存储区域
- listView动态加载数据分页
- 英语音标 语言、语音、音素及音标
- 【玩转cocos2d-x之三十六】Flappy Bird大集结
- json格式数据,将数据库中查询的结果转换为json, 然后调用接口的方式返回json(方式一)...
- android画布一闪一闪的,解决Android SurfaceView绘制触摸轨迹闪烁问题的方法
- [Leetcode 376]摇摆序列 Wiggle Subsequence
- mysql ubuntu 17.04_1、mysql 5.7 ubuntu17.04
- 认证Authentication
- java取消科学计数法_Jmeter、Java当double显示的数字过长时取消科学计数法显示
- uat测试用例和sit测试用例_集成测试和UAT测试(8.7)
- java 采集器_使用jsoup来写小说采集器
- 精简版oracle客户端程序
- [十大谬论]常见的逻辑谬误与批判方法
- 阿里巴巴的业务范畴/文化和价值观
- 敏捷管理 -- 时间和成本管理
- 将淘宝爬取的数据写入Excel表格
- 数字图像处理与Python实现-沃尔什-哈达玛变换(Walsh-Hadmard Transform,WHT)
- 华为云yum镜像源超慢改用阿里云镜像遇坑解决方法
- #NAME?_#NAME?:EXCEL表中出现#NAME是什么意思?
热门文章
- html input url,HTML5表单之Input 部类-url
- PHP exec() has been disabled for security reasons
- PHP调用微信发放现金红包接口
- $.ajax()常用属性
- easyui输入框模糊查询
- 浙大计算机学院陈越老师,浙江大学计算机科学与技术学院导师介绍 陈越
- 来面试,偷懒不答题,直接忽略
- 运行可用:使用FreeType输出中文汉字点阵图形的源码
- ImportError: No module named tensorrt
- 入住互联网酒店平台的体验