LibVlcSharp.WPF Reopen closed window in ForegroundWindow
What is the current bug behavior?
When I try Dock VLC Wpf window by DevExpress DockController, get VLCException("Unable to create WPF Window in VideoView.");
Relevant logs and/or screenshots
Exception: LibVLCSharp.Shared.VLCException Message: Unable to create WPF Window in VideoView. StackTrace: w LibVLCSharp.WPF.ForegroundWindow.Background_Loaded(Object sender, RoutedEventArgs e) w System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) w System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) w System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent) w System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root) w System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) w System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) Source: LibVLCSharp.WPF
Environment
- OS: Windows 10
- Device: PC
- LibVLC version and architecture [3.0.7.1, x86]
- LibVLCSharp version [3.1.0]
Possible fixes
When I don't close window in
void Wndhost_Closing(object sender, System.ComponentModel.CancelEventArgs e) { Hide(); }
Work fine, but It's not elegant way. I would do recreated window when is closed (only in Wndhost_SizeChanged and Wndhost_LocationChanged) Example:
void Wndhost_SizeChanged(object sender, SizeChangedEventArgs e)
{
var locationFromScreen = _bckgnd.PointToScreen(_zeroPoint);
if(_isWindowClosed)
CreateNewWindow();
var source = PresentationSource.FromVisual(_wndhost);
var targetPoints = source.CompositionTarget.TransformFromDevice.Transform(locationFromScreen);
Left = targetPoints.X;
Top = targetPoints.Y;
var size = new Point(_bckgnd.ActualWidth, _bckgnd.ActualHeight);
Height = size.Y;
Width = size.X;
}
void CreateNewWindow()
{
_wndhost = GetWindow(_bckgnd);
Trace.Assert(_wndhost != null);
Owner = _wndhost;
_wndhost.Closing += Wndhost_Closing;
_bckgnd.SizeChanged += Wndhost_SizeChanged;
_wndhost.LocationChanged += Wndhost_LocationChanged;
_isWindowClosed = false;
}