silverlight.2.0:Silverlight(5) - 2.0Control控件的ListBox MediaElement MultiScaleImage PasswordBox P

  本文源代码下载地址:

  http://flashview.ddvip.com/2008_11/Silverlight.rar

  在线DEMO

  http://www.cnblogs.com/webabcd/archive/2008/10/09/1307486.html

  举例

  1、ListBox.xaml

<UserControl x:Class="Silverlight20.Control.ListBox"
  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>


  ListBox.xaml.cs

using ;
using .Collections.Generic;
using .Linq;
using .Net;
using .Windows;
using .Windows.Controls;
using .Windows.Documents;
using .Windows.Input;
using .Windows.Media;
using .Windows.Media.Animation;
using .Windows.Shapes;
  
using .Windows.Browser;
  
Silverlight20.Control
{
  public partial ListBox : UserControl
  {
    public ListBox
    {
      InitializeComponent;
    }
  
    private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
      // ListBox.SelectedItem - ListBox中被选中对象
  
      var lst = sender as .Windows.Controls.ListBox;
  
      MessageBox.Show(
        ((.Windows.Controls.ListBoxItem)lst.SelectedItem).Content + " 被单击了",
        "提示",
        MessageBoxButton.OK);
    }
  }
}


  2、MediaElement.xaml

<UserControl x:Class="Silverlight20.Control.MediaElement"
  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>


  MediaElement.xaml.cs

using ;
using .Collections.Generic;
using .Linq;
using .Net;
using .Windows;
using .Windows.Controls;
using .Windows.Documents;
using .Windows.Input;
using .Windows.Media;
using .Windows.Media.Animation;
using .Windows.Shapes;
  
Silverlight20.Control
{
  public partial MediaElement : UserControl
  {
    public MediaElement
    {
      InitializeComponent;
    }
  
    void play_Click(object sender, RoutedEventArgs e)
    {
      var tb = sender as .Windows.Controls.Primitives.ToggleButton;
       (tb.IsChecked true)
      {
        tb.Content = "暂停";
  
        // MediaElement.Play - 播放视频
        this.mediaElement.Play;
      }
      
      {
        tb.Content = "播放";
  
        // MediaElement.Pause - 暂停视频
        // MediaElement.Stop - 停止视频
        this.mediaElement.Pause;
      }
    }
  
    void mute_Click(object sender, RoutedEventArgs e)
    {
      var tb = sender as .Windows.Controls.Primitives.ToggleButton;
       (tb.IsChecked true)
      {
        tb.Content = "有声";
  
        // MediaElement.IsMuted - 是否静音
        // MediaElement.Volume - 声音大小(0 - 1)
        this.mediaElement.IsMuted = true;
      }
      
      {
        tb.Content = "静音";
        this.mediaElement.IsMuted = false;
      }
    }
  }
}


  3、MultiScaleImage.xaml

<UserControl x:Class="Silverlight20.Control.MultiScaleImage"
  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>


  MultiScaleImage.xaml.cs(支持放大/缩小/拖动/滚轮的类摘自Deep Zoom Composer生成代码)

using ;
using .Collections.Generic;
using .Linq;
using .Net;
using .Windows;
using .Windows.Controls;
using .Windows.Documents;
using .Windows.Input;
using .Windows.Media;
using .Windows.Media.Animation;
using .Windows.Shapes;
  
Silverlight20.Control
{
  public partial MultiScaleImage : UserControl
  {
    //
    // Based _disibledevent="200" />
      </RadioButton.Content>
    </RadioButton>
    
  </StackPanel>
</UserControl>




  OK



Tags:  silverlight是什么 silverlight listbox控件 silverlight.2.0

延伸阅读

最新评论

发表评论