我有一个由Caliburn.Micro显示的窗口。此窗口包含可以播放YouTube视频的WebBrowser控件。如果正在播放Youtube视频并且用户关闭窗口,则音频将继续在后台播放。当窗口关闭时,如何让音频停止播放?我认为这个观点由于某种原因没有被处理掉。
显示窗口
public void Handle(VideoButtonClick message)
{
var manager = new WindowManager();
Video = new VideoViewModel(message.VideoID);
dynamic settings = new ExpandoObject();
settings.ResizeMode = ResizeMode.NoResize;
settings.Icon = null;
manager.ShowDialog(Video, null, settings);
}
在窗口中显示的视图
<UserControl .....>
<Grid>
<WebBrowser ctrl:BrowserBehavior.Html="{Binding VideoHTML}"
ScrollViewer.CanContentScroll="False"
ScrollViewer.VerticalScrollBarVisibility="Hidden" />
</Grid>
</UserControl>
答案 0 :(得分:0)
您可以在IDeactivate
:
VideoViewModel
public class VideoViewModel : PropertyChangedBase, IDeactivate
{
private bool _isClosing;
public bool IsClosing
{
get { return _isClosing; }
set
{
_isClosing = value;
NotifyOfPropertyChange(() => IsClosing);
}
}
public void Deactivate(bool close)
{
IsClosing = close;
}
public event EventHandler<DeactivationEventArgs> AttemptingDeactivation;
public event EventHandler<DeactivationEventArgs> Deactivated;
}
在Deactivate
方法中设置名为IsClosing
的属性。
在您看来:
<UserControl .....
x:Name="ThisUserControl">
<i:Interaction.Triggers>
<ei:DataTrigger Binding="{Binding IsClosing}" Value="True">
<ei:CallMethodAction MethodName="DisposeBrowser" TargetObject="{Binding ElementName=ThisUserControl}"/>
</ei:DataTrigger>
</i:Interaction.Triggers>
<Grid>
<WebBrowser x:Name="MyWebBrowser"
ctrl:BrowserBehavior.Html="{Binding VideoHTML}"
ScrollViewer.CanContentScroll="False"
ScrollViewer.VerticalScrollBarVisibility="Hidden" />
</Grid>
</UserControl>
在UserControl
:
public void DisposeBrowser()
{
MyWebBrowser.Dispose();
}