设置 MediaElement WPF 应用程序的 LoadedBehaviour 和 UnloadedBehaviour(C#)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19852537/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 10:01:37  来源:igfitidea点击:

Setting the LoadedBehaviour and UnloadedBehaviour of MediaElement WPF Application(C#)

c#wpfmediaelement

提问by Anoushka Seechurn

I am playing a video in a MediaElementin a WPF application. However when I am programatically invoking the Play(), Pause()or Stop()I get an error message saying:

我正在MediaElementWPF 应用程序中播放视频。但是,当我以编程方式调用Play(),Pause()或者Stop()我收到一条错误消息时说:

Cannot control media unless LoadedBehavior or UnloadedBehavior is set to Manual.

除非 LoadedBehavior 或 UnloadedBehavior 设置为手动,否则无法控制媒体。

I have no idea about it.

我不知道。

Can someone tell me how can these be set to MANUAL?

有人能告诉我如何设置这些MANUAL吗?

回答by Toan Nguyen

In XAML you can set the value to the properties like this:

在 XAML 中,您可以将值设置为如下属性:

<MediaElement x:Name="player"
              LoadedBehavior="Manual"
              UnloadedBehavior="Stop" ... />                  

Or using code behind:

或者使用后面的代码:

player.LoadedBehavior = MediaState.Manual;
player.UnloadedBehavior = MediaState.Stop;