epj.AspectView.Forms
1.0.1-pre
dotnet add package epj.AspectView.Forms --version 1.0.1-pre
NuGet\Install-Package epj.AspectView.Forms -Version 1.0.1-pre
<PackageReference Include="epj.AspectView.Forms" Version="1.0.1-pre" />
paket add epj.AspectView.Forms --version 1.0.1-pre
#r "nuget: epj.AspectView.Forms, 1.0.1-pre"
// Install epj.AspectView.Forms as a Cake Addin #addin nuget:?package=epj.AspectView.Forms&version=1.0.1-pre&prerelease // Install epj.AspectView.Forms as a Cake Tool #tool nuget:?package=epj.AspectView.Forms&version=1.0.1-pre&prerelease
epj.AspectView.Forms
A type of ContentView for Xamarin.Forms that resizes itself based on the provided aspect ratio.
Summary
Sometimes, when dealing with video views, I got extremely frustrated, because there was no practical way to keep the video view exactly in the size ratio of the video itself without letterboxing or stretching.
I could set the WidthRequest
and HeightRequest
properties according to the size ratio of the video, but then I wouldn't have the option to stretch the video across the entire screen width or height using the HorizontalOptions
or VerticalOptions
.
This is how the AspectView was conceived. It's a container for other ContentViews and always keeps the size ratio that you have set, which means you can box your video view, images or anything else inside of it, provide a size ratio and avoid letterboxing and stretching.
Preview
<div> <img src="assets/portrait.jpg" align="top" width="240" /> <img src="assets/landscape.jpg" align="top" height="240" /> </div> <br />
This looks suspiciously similar like letterboxing, however it's not. In the case of letterboxing, the background would be black while we can actually see the Page background here, which means that we could add other controls and maintain the video's aspect without letterboxing.
Usage
Simply install the package from nuget.org and then use it as follows:
<Grid>
<forms:AspectView
AspectRatio="0.5625"
HorizontalOptions="Fill"
VerticalOptions="Center">
<videoPlayer:VideoPlayer
Source="myvideo.mp4" />
</forms:AspectView>
</Grid>
If you want to use a 16:9 ratio for videos, you would use 0.5625, like in the example.
Important
The <em>AspectView</em> control uses the HorizontalOptions
and VerticalOptions
in combination with the AspectRatio
property and only works when either the HorizontalOptions
or the VerticalOptions
property is set to Fill
, but not both at the same time.
Note: The AspectRatio
must have a value greater than 0.0
and by default is set to 1.0
, which means square.
Acknowledgements
Video by <a href="https://pixabay.com/users/meditation_hypnosis-25780195/?utm_source=link-attribution&utm_medium=referral&utm_campaign=video&utm_content=113403">Ivan</a> from <a href="https://pixabay.com//?utm_source=link-attribution&utm_medium=referral&utm_campaign=video&utm_content=113403">Pixabay</a>
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- CommunityToolkit.Diagnostics (>= 8.0.0)
- Xamarin.Forms (>= 5.0.0.2545)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.1-pre | 163 | 2/17/2023 |
1.0.0 | 314 | 2/3/2023 |
0.1.3-alpha | 168 | 1/4/2023 |
0.1.2-alpha | 163 | 12/22/2022 |
0.1.1-alpha | 142 | 12/22/2022 |
0.1.0-alpha | 165 | 12/22/2022 |