代码改变世界

silverlight系列(DataGrid、DataPager、TreeView、MediaElement)

2010-02-23 13:03  key_sky  阅读(1035)  评论(0编辑  收藏  举报

DataPager:

  • AutoEllipsis:是否使用省略号做为最后的数值按钮。
  • DisplayMode:分页的用户界面模式。
  • ItemCount:元数据集中已知项的当前数目。
  • NumericButtonCount:用户界面上显示的页按钮的数目。
  • PageCount:获取已知页的当前数目。
  • PageIndex:获取或设置当前页的索引。
  • PageSize:页面上显示的页的数目。

MediaElement:

  • Source:文件路径,以html页为基准,若无法显示可以直接放入clientbin文件夹下。
  • Pause:当前位置暂停媒体。
  • Play:当前位置播放媒体。
  • Stop:停止媒体并将其从头开始播放。
  • AudioStreamCount:当前媒体文件中可用的文件数目。
  • AudioStreamIndex:与视频组件一起播放的音频流的索引。音频流的集合在运行时组合,它表示可用于媒体文件内的所有音频流。
  • AutoPlay:加载时媒体是否自动开始播放。
  • Balance:立体声扬声器的音量比。范围为-1到1,默认值为0(左右扬声器之间平均分布音量)。
  • BufferingProgress:当前缓冲进度的值。
  • BufferingGTime:缓冲的时间量。
  • CanPause:媒体播放时是否可以暂停。
  • CanSeek:是否可以通过Position属性重新定位媒体。
  • CurrentState:获取媒体当前状态。
  • DownloadProgress:位于远程服务器上的内容下载的百分比量。
  • DownloadProgressOffset:下载进度的偏移量。
  • DroppedFramesPerSecond:获取媒体每秒正在丢弃的帧数。
  • IsMuted:获取或设置当前媒体是否静音。
  • NaturalDuration:当前打开媒体的持续时间。
  • NaturalVideoHeight:获取当前视频的高度。
  • NaturalVideoWidth:获取当前视频的宽度。
  • Position:媒体播放时间的当前进度的位置,必须先将CanSeek属性设置为true格式为"Hours:Minutes:Seconds"
    RenderedFramesPerSecond:获取媒体每秒正在播放的秒数。
  • Stretch:设置媒体如何填充矩形区域。
  • Volume:获取或设置媒体的音量,在0-1之间,默认值为0.5。

XAML:

<UserControl xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
x:Class
="DataShowControl.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="150"/>
<RowDefinition Height="50"/>
<RowDefinition Height="150"/>
<RowDefinition Height="35"/>
<RowDefinition Height="60"/>
<RowDefinition Height="35"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="450" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<data:DataGrid x:Name="DG1" VerticalAlignment="Top" GridLinesVisibility="All"
Width="400" Height="140" Background="AliceBlue" AutoGenerateColumns="True" Grid.Row="0" >
</data:DataGrid>
<data:DataPager x:Name="DP1" Grid.Row="1" AutoEllipsis="True" DisplayMode="FirstLastPreviousNext" >
</data:DataPager>
<!--
AutoEllipsis:是否使用省略号做为最后的数值按钮
DisplayMode:分页的用户界面模式
ItemCount:元数据集中已知项的当前数目
NumericButtonCount:用户界面上显示的页按钮的数目
PageCount:获取已知页的当前数目
PageIndex:获取或设置当前页的索引
PageSize:页面上显示的页的数目
-->
<controls:TreeView x:Name="tvw1" Height="150" Grid.Row="2" Background="AliceBlue"
Width="450">
<controls:TreeViewItem Header="TreeViewItem containing other items.">
<controls:TreeViewItem.Items>
<controls:TreeViewItem>
<controls:TreeViewItem.Header>
<StackPanel Orientation="Horizontal">
<Image Height="15" Width="15" Source="Image/botton_gif_010.gif" />
<TextBlock Text="Item 1" Margin="2"/>
</StackPanel>
</controls:TreeViewItem.Header>
</controls:TreeViewItem>
<controls:TreeViewItem>
<controls:TreeViewItem.Header>
<StackPanel Orientation="Horizontal">
<Image Height="15" Width="15" Source="Image/botton_png_006.png" />
<TextBlock Text="Item 2" Margin="2"/>
</StackPanel>
</controls:TreeViewItem.Header>
</controls:TreeViewItem>
</controls:TreeViewItem.Items>
</controls:TreeViewItem>
</controls:TreeView>
</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;
using System.Windows.Data;

namespace DataShowControl
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
DataBind();

}
private void DataBind()
{
List
<string> list1 = new List<string>();
for (int i = 0; i < 50; i++)
{
list1.Add(
"ListItem" + i.ToString());
}
DG1.ItemsSource
= list1;
PagedCollectionView listview
= new PagedCollectionView(list1);
DP1.Source
= listview;
}
}
}

运行结果:

ImageVideo.Xaml:

<UserControl x:Class="ImageVideo.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="68"/>
<RowDefinition Height="200"/>
<RowDefinition Height="25"/>
<RowDefinition Height="35"/>
<RowDefinition Height="60"/>
<RowDefinition Height="35"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300" />
<ColumnDefinition Width="80" />
<ColumnDefinition Width="80" />
<ColumnDefinition Width="80" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Image Source="Image1/2.png" Grid.Row="0" Width="257" Height="68" Grid.Column="0" ></Image>
<!--
Source:图片路径,支持绝对路径
-->
<MultiScaleImage x:Name="msi1" Grid.Row="5" Source="Image1/2.png" Width="257" Height="68"
Grid.Column="0"></MultiScaleImage>
<MediaElement x:Name="me1" Source="2.wmv" Width="300" Height="200" Grid.Row="1"
  Grid.Column="0" AutoPlay="True" IsMuted="False" Stretch="Fill" Volume="0.5"
BufferingProgressChanged="me1_BufferingProgressChanged" CurrentStateChanged="me1_CurrentStateChanged"
MediaEnded="me1_MediaEnded" MediaOpened="me1_MediaOpened" ></MediaElement>
<Button x:Name="btnstop" Content="停止" Grid.Row="2" Width="70" Height="25"
Grid.Column="0" Click="btnstop_Click"></Button>
<Button x:Name="btnplay" Content="播放" Grid.Row="2" Width="70" Height="25"
Grid.Column="1" Click="btnplay_Click"></Button>
<Button x:Name="btnpause" Content="暂停" Grid.Row="2" Width="70" Height="25"
Grid.Column="2" Click="btnpause_Click"></Button>
<Button x:Name="btnMuted" Content="静音" Grid.Row="2" Width="70" Height="25"
Grid.Column="3" Click="btnMuted_Click"></Button>
<Button x:Name="btnFullScreen" Content="全屏" Grid.Row="2" Width="70" Height="25"
Grid.Column="4" Click="btnFullScreen_Click"></Button>
<!--
Source:文件路径,以html页为基准,若无法显示可以直接放入clientbin文件夹下
Pause:当前位置暂停媒体
Play:当前位置播放媒体
Stop:停止媒体并将其从头开始播放
AudioStreamCount:当前媒体文件中可用的文件数目
AudioStreamIndex:与视频组件一起播放的音频流的索引。音频流的集合在运行时组合,
它表示可用于媒体文件内的所有音频流
AutoPlay:加载时媒体是否自动开始播放
Balance:立体声扬声器的音量比。范围为-1到1,默认值为0(左右扬声器之间平均分布音量)
BufferingProgress:当前缓冲进度的值
BufferingGTime:缓冲的时间量
CanPause:媒体播放时是否可以暂停
CanSeek:是否可以通过Position属性重新定位媒体
CurrentState:获取媒体当前状态
DownloadProgress:位于远程服务器上的内容下载的百分比量
DownloadProgressOffset:下载进度的偏移量
DroppedFramesPerSecond:获取媒体每秒正在丢弃的帧数
IsMuted:获取或设置当前媒体是否静音
NaturalDuration:当前打开媒体的持续时间
NaturalVideoHeight:获取当前视频的高度
NaturalVideoWidth:获取当前视频的宽度
Position:媒体播放时间的当前进度的位置,必须先将CanSeek属性设置为true格式为
"Hours:Minutes:Seconds"
RenderedFramesPerSecond:获取媒体每秒正在播放的秒数
Stretch:设置媒体如何填充矩形区域
Volume:获取或设置媒体的音量,在0-1之间,默认值为0.5
-->

</Grid>
</UserControl>

ImageVideo.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.Interop;

namespace ImageVideo
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
/// <summary>
///当 BufferingProgress 属性更改时发生。
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void me1_BufferingProgressChanged(object sender, RoutedEventArgs e)
{

}
/// <summary>
/// 当 CurrentState 属性的值更改时发生。
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void me1_CurrentStateChanged(object sender, RoutedEventArgs e)
{
MessageBox.Show(me1.CurrentState.ToString());
}
/// <summary>
/// 当 MediaElement 不再播放音频或视频时发生。
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void me1_MediaEnded(object sender, RoutedEventArgs e)
{
MessageBox.Show(
"播放完毕,历时:" + me1.NaturalDuration.ToString());
}
/// <summary>
/// 当媒体流已被验证和打开且已读取文件头时发生。
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void me1_MediaOpened(object sender, RoutedEventArgs e)
{
MessageBox.Show(
"开始播放");
}

private void btnstop_Click(object sender, RoutedEventArgs e)
{
me1.Stop();
}

private void btnplay_Click(object sender, RoutedEventArgs e)
{
me1.Play();
}

private void btnpause_Click(object sender, RoutedEventArgs e)
{
me1.Pause();
}

private void btnMuted_Click(object sender, RoutedEventArgs e)
{
me1.IsMuted
= true;
}

private void btnFullScreen_Click(object sender, RoutedEventArgs e)
{
Application.Current.Host.Content.IsFullScreen
= !Application.Current.Host.Content.IsFullScreen;
}
}
}

运行结果: