New Features of Silverlight 5 beta: 9. Video fast forward and fast return and TextSearch object query of text items

Source: Internet
Author: User

This section describes two new features: 1. In Silverlight 5, you can control the video played by the MediaElement object for fast forward and backward control. 2. Search and query the text items in Silverlight 5.

1. Fast-forward control of videos played by MediaElement Media

It is controlled through the MediaElement. PlaybackRate attribute. Currently, this attribute only supports seven parameters:-8.0,-4.0, 0.5, 1.0, 2.0, and 4.0, that is to say, it is 8 times faster, 4 times faster, 0.5 times slower, normal, 2 times faster, 4 times faster, and 8 times faster. Now let's take a look at the MediaElement object control source code in this instance as follows:

// Control the playback speed
Int flag = 0;
Private void button6_Click (object sender, RoutedEventArgs e)
{
If (flag = 0)
{
This. showVideo. PlaybackRate = 0.5;
}
Else if (flag = 1)
{
This. showVideo. PlaybackRate = 1.0;
}
Else if (flag = 2)
{
This. showVideo. PlaybackRate = 2.0;

}
Else if (flag = 3)
{
This. showVideo. PlaybackRate = 4.0;

}
Else if (flag = 4)
{
This. showVideo. PlaybackRate = 8.0;
Flag = 0;
Return;
}
Flag ++;
}

The effect preview is as follows:

2. TextSearch object query text items

It is a new TextSearch class added in Silverlight 5. Set TextSearch. TextPath = "FirstName" in all text controls with Item attributes (such as ComboBox and ListBox. Of course, FirstName is a field bound to the source class. The source code of XAML is as follows:

        <ListBox ItemsSource="{Binding}"               TextSearch.TextPath="FirstName"               Width="176"               Height="363"               HorizontalAlignment="Center"               VerticalAlignment="Center"               DisplayMemberPath="FirstName" Margin="610,31,214,106" />        <ComboBox ItemsSource="{Binding}"               TextSearch.TextPath="FirstName"               Width="137"               Height="30"               HorizontalAlignment="Center"               VerticalAlignment="Center"               DisplayMemberPath="FirstName" Margin="797,31,66,439" />

The following binding is required in the cs code:

      public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();

BindListData();
private void BindListData()
{
DataContext = new List<User>()
{
new User()
{
FirstName= "liusan",
Age=20
},
new User()
{
FirstName= "liyun",
Age=20
},
new User()
{
FirstName= "liulin",
Age=20
},
new User()
{
FirstName= "mingtian",
Age=20
},
new User()
{
FirstName= "jintian",
Age=20
},
new User()
{
FirstName= "shanghai",
Age=20
},
new User()
{
FirstName= "chengdu",
Age=20
},
new User()
{
FirstName= "luntai",
Age=20
},
new User()
{
FirstName= "shenming",
Age=20
},
new User()
{
FirstName= "edison",
Age=20
},
new User()
{
FirstName= "jeson",
Age=20
},
new User()
{
FirstName= "jiufen",
Age=20
},
new User()
{
FirstName= "jiuding",
Age=20
},
new User()
{
FirstName= "shenfenzheng",
Age=20
}
}.OrderBy(x => x.FirstName);
}
}

public class User
{
public String FirstName
{
get;
set;
}
public Int32 Age
{
get;
set;
}
}

Finally, when the focus is obtained in ComboBox or ListItem, you can press the English character on the keyboard to automatically find the corresponding Item. This example is written in VS2010 + Silverlight 5 beta. If you need the source code, click SLTextSearch.zip to download it. Now let's see the following:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.