You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I came up with a very simple, but effective fix for libvlcsharp.avalonia not scaling in a viewbox in Avalonia. You put the videoview inside a viewbox as you normally would and subscribe to bounds changes on the viewbox:
_boundsSubscription = _viewbox.GetObservable(Viewbox.BoundsProperty)
.Subscribe(newBounds => OnViewboxBoundsChanged(newBounds));
private void OnViewboxBoundsChanged(Rect newBounds)
{
if (_viewbox == null || _videoView == null)
return;
var newSize = newBounds.Size;
if (newSize == _lastViewboxSize || newSize.Width <= 0 || newSize.Height <= 0)
return;
_lastViewboxSize = newSize;
// Calculate the scaled size of the VideoView within the Viewbox
// Viewbox uses Uniform stretch, so we need to calculate aspect-ratio-preserving size
const double videoWidth = 400;
const double videoHeight = 300;
var videoAspect = videoWidth / videoHeight; // 4:3 ratio
var viewboxAspect = newSize.Width / newSize.Height;
double scaledWidth, scaledHeight;
if (viewboxAspect > videoAspect)
{
// Viewbox is wider - constrain by height
scaledHeight = newSize.Height;
scaledWidth = scaledHeight * videoAspect;
}
else
{
// Viewbox is taller - constrain by width
scaledWidth = newSize.Width;
scaledHeight = scaledWidth / videoAspect;
}
var newWidth = Math.Max(1, scaledWidth);
var newHeight = Math.Max(1, scaledHeight);
// Update VideoView size to match the scaled size
_videoView.Width = newWidth;
_videoView.Height = newHeight;
// Force layout update to ensure native window resizes
_videoView.InvalidateMeasure();
_videoView.InvalidateArrange();
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I came up with a very simple, but effective fix for libvlcsharp.avalonia not scaling in a viewbox in Avalonia. You put the videoview inside a viewbox as you normally would and subscribe to bounds changes on the viewbox:
Beta Was this translation helpful? Give feedback.
All reactions