作者chris75123 (123)
看板C_Sharp
标题Re: [问题] 取得MediaElement.Source
时间Fri Mar 18 15:13:21 2011
using System.Windows.Shapes;
using System.Windows.Threading;
using Microsoft.Surface.Presentation;
using Microsoft.Surface.Presentation.Controls;
using Microsoft.Surface.Presentation.Input;
using SSC = Microsoft.Surface.Presentation.Controls;
namespace CourseIntegrator_Player
{
const string systemFoldersKey = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\explorer\Shell Folders";
videoPuzzlesPath = (string)Microsoft.Win32.Registry.GetValue(systemFoldersKey, "CommonVideo", null) + @"\Sample Videos";
InitializeComponent();
LoadPhotos();
}
private void LoadPhotos()
{
foreach (string file in Directory.GetFiles(videoPuzzlesPath, "*.wmv"))
{
MediaElement video = new MediaElement();
MediaTimeline t = new MediaTimeline();
t.Source = new Uri(file);
t.RepeatBehavior = RepeatBehavior.Forever;
video.Clock = t.CreateClock();
video.IsMuted = true;
video.Clock.Controller.Begin();
AddElementToPhotoList(video);
}
}
private void AddElementToPhotoList(UIElement img)
{
Viewbox b = new Viewbox { Width = 200, Child = img };
photo.Items.Insert(photo.Items.Count, b);
}
private void photo_SelectionChanged(object sender, SelectionChangedEventArgs
e)
{ //将从SurfaceListBox选到的item加到ScatterView里 photo是SurfaceListBox的name
SSC.ScatterViewItem item = new SSC.ScatterViewItem();
Viewbox vb = (Viewbox)photo.SelectedItem;
MediaElement Movie = (MediaElement)vb.Child;
item.Content = Movie;
scatter.Items.Add(item);
}
※ 引述《chris75123 (123)》之铭言:
: 抓SurfaceListBox上点选的影片的档案路径
: ===============================================
: photo是SurfaceListBox元件
: Viewbox vb = (Viewbox)photo.SelectedItem;
: MediaElement Movie = (MediaElement)vb.Child;
: MessageBox.Show(Movie.Source.ToString());
: 想要取得点选的item的source但是一直出现这个错误
: "MessageBox.Show(Movie.Source.ToString())"
: 并未将物件参考设定为物件的执行个体。
: 用debugger看了一下Movie.source是null @@
: ================================================
: 但是如果vb.Child改用Image接就抓得到Source
: 可以抓到图片的抓不到影片的
: 为什麽阿QQ??
: 麻烦各位了!!谢谢大家!!!
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.123.105.52
1F:→ chris75123:问题是 item.Content = Movie这行 03/18 15:23
2F:→ chris75123:指定的项目已经是另一个项目的子项目。请先中断连线。 03/18 15:23