admin管理员组文章数量:1415119
My goal is to create different Avalonia UI applications for specific screen resolutions. For example 4k or some specific portrait orientation. During development, I would like to scale the GUI to match smaller developer's screen sizes keeping UI elements and margins proportional. The Avalonia.Controls.Viewbox
seems to perfectly meet this requirement. However, a nested LibVLCSharp.Avalonia.VideoView
used to play a video does not scale with the rest of the GUI.
Is there any solution or workaround?
Current sample code:
<Window xmlns=";
xmlns:x=";
xmlns:vm="using:VLCTest.ViewModels"
xmlns:d=";
xmlns:mc=";
xmlns:avalonia="clr-namespace:LibVLCSharp.Avalonia;assembly=LibVLCSharp.Avalonia"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="VLCTest.Views.MainWindow"
x:DataType="vm:MainWindowViewModel"
Icon="/Assets/avalonia-logo.ico"
Title="VLCTest"
Width="400"
Height="300">
<!-- The Viewbox scales the GUI to match the window size -->
<Viewbox>
<!-- Create a panel that matches the target screen size
This small size is for demonstration purpose only. Typical use cases
contain higher resolutions than the developer's screen size.
The panel size is set to the same size as the window for demonstration purposes.
It will later be a full screen application
and match the target screen resolution.-->
<Panel Width="400" Height="300">
<Grid RowDefinitions="Auto,Auto,*" ShowGridLines="True">
<!-- Button that scales as expected -->
<Button Grid.Row="0">Test Button 1</Button>
<!-- VideoView as well as the contained Button do not scale as expected -->
<avalonia:VideoView Grid.Row="1"
HorizontalAlignment="Center"
Height="200"
Width="200"
MediaPlayer="{Binding MediaPlayer}">
<Panel>
<Button VerticalAlignment="Center" HorizontalAlignment="Center">Test Button 2</Button>
</Panel>
</avalonia:VideoView>
<!-- Remaining space that scales as expected -->
<Panel Grid.Row="2" Background="Gray">
<TextBlock>Remaining Space</TextBlock>
</Panel>
</Grid>
</Panel>
</Viewbox>
</Window>
Screenshot of the GUI with default window size: Default Window Size
Screenshot of the Window sized down to a smaller size: Smaller Window
- The Test Button 1 is scaled as expected.
- The Remaining Space is scaled as expected.
- The Grid row containing the
VideoView
is scaled as expected. - The
VideoView
stays at the same size (at least the rendered video) while changing its position. - The rendered video therefore overlaps into the row with the Remaining Space.
- The Test Button 2 stays at the same size while changing its position.
The source code of the VideoView
can be found in libvlcsharp/src/LibVLCSharp.Avalonia/VideoView.cs. However, I couldn't manage to understand how everything works together and why the scaling of the Viewbox
does not apply to the rendered video.
My goal is to create different Avalonia UI applications for specific screen resolutions. For example 4k or some specific portrait orientation. During development, I would like to scale the GUI to match smaller developer's screen sizes keeping UI elements and margins proportional. The Avalonia.Controls.Viewbox
seems to perfectly meet this requirement. However, a nested LibVLCSharp.Avalonia.VideoView
used to play a video does not scale with the rest of the GUI.
Is there any solution or workaround?
Current sample code:
<Window xmlns="https://github/avaloniaui"
xmlns:x="http://schemas.microsoft/winfx/2006/xaml"
xmlns:vm="using:VLCTest.ViewModels"
xmlns:d="http://schemas.microsoft/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats./markup-compatibility/2006"
xmlns:avalonia="clr-namespace:LibVLCSharp.Avalonia;assembly=LibVLCSharp.Avalonia"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="VLCTest.Views.MainWindow"
x:DataType="vm:MainWindowViewModel"
Icon="/Assets/avalonia-logo.ico"
Title="VLCTest"
Width="400"
Height="300">
<!-- The Viewbox scales the GUI to match the window size -->
<Viewbox>
<!-- Create a panel that matches the target screen size
This small size is for demonstration purpose only. Typical use cases
contain higher resolutions than the developer's screen size.
The panel size is set to the same size as the window for demonstration purposes.
It will later be a full screen application
and match the target screen resolution.-->
<Panel Width="400" Height="300">
<Grid RowDefinitions="Auto,Auto,*" ShowGridLines="True">
<!-- Button that scales as expected -->
<Button Grid.Row="0">Test Button 1</Button>
<!-- VideoView as well as the contained Button do not scale as expected -->
<avalonia:VideoView Grid.Row="1"
HorizontalAlignment="Center"
Height="200"
Width="200"
MediaPlayer="{Binding MediaPlayer}">
<Panel>
<Button VerticalAlignment="Center" HorizontalAlignment="Center">Test Button 2</Button>
</Panel>
</avalonia:VideoView>
<!-- Remaining space that scales as expected -->
<Panel Grid.Row="2" Background="Gray">
<TextBlock>Remaining Space</TextBlock>
</Panel>
</Grid>
</Panel>
</Viewbox>
</Window>
Screenshot of the GUI with default window size: Default Window Size
Screenshot of the Window sized down to a smaller size: Smaller Window
- The Test Button 1 is scaled as expected.
- The Remaining Space is scaled as expected.
- The Grid row containing the
VideoView
is scaled as expected. - The
VideoView
stays at the same size (at least the rendered video) while changing its position. - The rendered video therefore overlaps into the row with the Remaining Space.
- The Test Button 2 stays at the same size while changing its position.
The source code of the VideoView
can be found in libvlcsharp/src/LibVLCSharp.Avalonia/VideoView.cs. However, I couldn't manage to understand how everything works together and why the scaling of the Viewbox
does not apply to the rendered video.
1 Answer
Reset to default 0The Viewbox is an Avalonia thing, but the videoView is implemented using hwnd, which are not very avalonia-friendly. This i why there is this airspace hack in place for example.
Bug like that are generally limitations about what's doable with Avalonia, but if you can get that scaling and hack something so that it behaves the right way, you can try to submit a PR here : https://github/videolan/libvlcsharp
本文标签: net coreHow to use a LibVLCSharpAvaloniaVideoView within an AvaloniaControlsViewboxStack Overflow
版权声明:本文标题:.net core - How to use a LibVLCSharp.Avalonia.VideoView within an Avalonia.Controls.Viewbox? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745213367a2648018.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论