如何使用代码创建的 mediaElement 的名称并在另一个方法中使用其名称?
我正在使用 Visual Studio 2010,c# WPF。我在运行时创建了一个 MediaElement 控件;
MediaElement video= new MediaElement();
video.Width = 400;
video.Height = 400;
video.Play();
video.Source = new Uri(path, UriKind.Relative);
在 XAML 视图中,我创建了 2 个按钮:“播放”和“停止”,仅当创建了 mediaElement 时,它们才可见。但我需要将 click_events 添加到这两个按钮。但是当我写 video.Play();
它不知道这个名字。有谁知道如何让这个名字在这些单独的方法中被识别?
private void play_Click(object sender, RoutedEventArgs e)
{
video.Play(); //syntax error under video
}
private void stop_Click(object sender, RoutedEventArgs e)
{
video.Play(); //syntax error under video
}
I'm using Visual Studio 2010, c# WPF. I have created a MediaElement
control during runtime;
MediaElement video= new MediaElement();
video.Width = 400;
video.Height = 400;
video.Play();
video.Source = new Uri(path, UriKind.Relative);
In the XAML view I created 2 buttons, Play and Stop which I will show to be visible only if a mediaElement is created. But I need to add click_events to these 2 buttons. But when I write video.Play();
it does not know this name. Does anyone know how to get this name to be recognised in these seperate methods?
private void play_Click(object sender, RoutedEventArgs e)
{
video.Play(); //syntax error under video
}
private void stop_Click(object sender, RoutedEventArgs e)
{
video.Play(); //syntax error under video
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将
video
定义为成员变量。例如,假设您在一个名为MediaWindow
的类中...根据您的实际类结构和设置进行调整。
You need to define
video
as a member variable. For example, say you're in a class calledMediaWindow
...Adjust for your actual class structure and setup.