稳扎稳打Silverlight(5) - 2.0控件之ListBox, MediaElement, MultiScaleImage, PasswordBox, ProgressBar, RadioButton

稳扎稳打Silverlight(5) - 2.0控件之ListBox, MediaElement, MultiScaleImage, PasswordBox, ProgressBar, RadioButton,第1张

概述[索引页] [源码下载] 稳扎稳打Silverlight(5) - 2.0控件之ListBox, MediaElement, MultiScaleImage, PasswordBox, ProgressBar, RadioButton 作者: webabcd 介绍 Silverlight 2.0 控件一览:ListBox, MediaElement, MultiScaleImage, Passwo [索引页]
[源码下载]


稳扎稳打Silverlight(5) - 2.0控件之ListBox,MediaElement,MultiScaleImage,PasswordBox,Progressbar,Radiobutton

作者: webabcd


介绍
Silverlight 2.0 控件一览:ListBox,Radiobutton


在线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  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  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);

        }

    }

}



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  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 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)

            

@H_403_1296@{

                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)

            

@H_604_1502@{

                tb.Content 
= "有声";


                
// MediaElement.IsMuted - 是否静音

                
// MediaElement.Volume - 声音大小(0 - 1)

                this.mediaElement.IsMuted = true;

            }

            
else

            

{

                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  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 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, this.ActualHeight / 2));

        }

         * 
*/

    }

}



4、PasswordBox.xaml

< UserControl  x:Class ="Silverlight20.Control.PasswordBox"

    xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  

    xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml" >

    
< StackPanel  HorizontalAlignment ="left" >

        

        
<!--

        Password - PasswordBox控件的密码值

        PasswordChar - PasswordBox控件所显示的密码替代字符。默认值为“●”

        
-->

        
< PasswordBox  WIDth ="200"  PasswordChar ="*" ></ PasswordBox >

        

    
</ StackPanel >     

</ UserControl >



5、Progressbar.xaml

< UserControl  x:Class ="Silverlight20.Control.Progressbar"

    xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  

    xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml" >

    
< StackPanel  HorizontalAlignment ="left" >

        

        
< TextBlock  x:name ="lblPercent"  TextAlignment ="Center"   />

        
<!--

        Minimum - Progressbar控件的最小值。参见基类System.windows.Controls.Primitives.RangeBase

        Maximum - Progressbar控件的最大值。参见基类System.windows.Controls.Primitives.RangeBase

        Value - Progressbar控件的值。参见基类System.windows.Controls.Primitives.RangeBase

        ValueChanged - Progressbar控件的值发生变化时所触发的事件

        
-->

        
< Progressbar  x:name ="progressbar"  WIDth ="200"  Height ="20"  Minimum ="10"  Maximum ="70" ></ Progressbar >


        
<!--

        IsIndeterminate - 是否无法确定当前的进度值

            false - 可以确定当前的进度值

            true - 无法确定当前的进度值。一个Loading动画

        
-->

        
< Progressbar  WIDth ="200"  Height ="20"  IsIndeterminate ="True"  margin ="5" ></ Progressbar >


   
</ StackPanel >

</ UserControl >


Progressbar.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 Progressbar : UserControl

    

{

        Storyboard _loop 
= new Storyboard();

        
int _count = 0;


        
public Progressbar()

        

{

            InitializeComponent();


            ProgressbarDemo();

        }


        
voID ProgressbarDemo()

        

{

            _loop.Duration 
= TimeSpan.FromMilliseconds(100d);

            _loop.Completed 
+= new EventHandler(_loop_Completed);

            _loop.Begin();

        }


        
voID _loop_Completed(object sender, EventArgs e)

@H_403_4026@

        
@H_409_4032@

@H_96_4037@{

            progressbar.Value 
= _count;

            lblPercent.Text 
= _count.ToString() + "%";


            
if (_count > 100)

                _count 
= 0;

            
else

                _count
++;


            _loop.Begin();

        }

    }

}



6、Radiobutton.xaml

< UserControl  x:Class ="Silverlight20.Control.Radiobutton"

    xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  

    xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml" >

    
< StackPanel  HorizontalAlignment ="left" >

        

        
<!--

        Groupname - Radiobutton控件所属组的组名

        Checked - 被选中后所触发的事件

        Click - 被单击后所触发的事件

        
-->

        
< Radiobutton  Groupname ="groupname"  Content ="红色的Radiobutton"  Background ="Red"  margin ="5"   />

        

        
<!--

        IsEnabled - Radiobutton是否有效

        
-->

        
< Radiobutton  Groupname ="groupname"  Content ="无效的Radiobutton"  IsEnabled ="False"  margin ="5"   />


        
<!--

        IsChecked - 是否被选中

        Radiobutton.Content - Radiobutton所对应的内容

        
-->

        
< Radiobutton  Groupname ="groupname"  margin ="5"  IsChecked ="true" >

            
< Radiobutton.Content >

                
< Image  Source ="/Silverlight20;component/Images/logo.jpg"  WIDth ="200"   />

            
</ Radiobutton.Content >

        
</ Radiobutton >

        

    
</ StackPanel >

</ UserControl >



OK
[源码下载] 总结

以上是内存溢出为你收集整理的稳扎稳打Silverlight(5) - 2.0控件之ListBox, MediaElement, MultiScaleImage, PasswordBox, ProgressBar, RadioButton全部内容,希望文章能够帮你解决稳扎稳打Silverlight(5) - 2.0控件之ListBox, MediaElement, MultiScaleImage, PasswordBox, ProgressBar, RadioButton所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1053675.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存