fit html based on user screen size using webView in MAUI - webview

In my MAUI application I'm using webview to display my existing static html pages. But it is giving me scrollbars horizontally and vertically. I want my html page to adjust itself based on screen-size of device.
I tried to set MaximumHeightRequest & MaximumWidthRequest but it didn't worked for me. I want to have a dynamic solution for this problem.

Are you looking for this https://github.com/dotnet/maui/issues/8241. Look for #MobileDev327 comments
<ContentPage .....>
<ScrollView>
<Grid>
<Grid>
<Label Text="By default, a Grid contains one row and one column" />
</Grid>
<Grid Padding="0,30,0,0">
<WebView x:Name="jsExampleWebView" Source="Map.html"/>
</Grid>
</Grid>
</ScrollView>
Windows
Android Emulator

Related

NativeScript: WebView with rounded corners (Android Only)

I want to have rounded corners in my WebView, but apparently the borderRadius directive is ignored in Android
<GridLayout rows="*">
<WebView row="0" id="webView" borderRadius="20 20 0 0"/>
</GridLayout>
Any idea?
This is the desired result:
I solved this problem by using cardview which has top preference on view hierarchy(I don't know what they call officially, I just telling you as view hierarchy to make some sense).
If you know how FAB will get placed on a view. You can understand how this works. For more info you need to dig into these developing-hierarchy (This might be a wrong tutorial, but I got only this)
solution
<Page xmlns:Card="#nstudio/nativescript-cardview">
<StackLayout>
<Card:CardView margin="10" radius="50">
<StackLayout height="500">
<WebView src="https://i.ytimg.com/vi/xRZB5KBLdOA/maxresdefault.jpg" />
</StackLayout>
</Card:CardView>
</StackLayout>
</Page>
For more info on this plugin nativescript-cardview
If you get more info on this share here.

Xamarin toolbar item on IOS not aligning properly

I am having difficulty in aligning a toolbar item to the far right on the IOS build of a Xamarin application, although, on the Android build, it works perfectly fine and aligns the toolbar item to the far right of the toolbar.
XML code for the toolbar item:
<ContentPage.ToolbarItems x:Uid="ToolbarName">
<ToolbarItem x:Name="Settings" Order="Primary" Icon="cog.png" Priority="0" Clicked="Settings_Clicked" />
</ContentPage.ToolbarItems>
IOS build toolbar:
I do not want to change the XML too much as I am worried that it will then effect the android build.
Any help on the matter would be greatly appreciated.
Thanks.
This is a known issue of the Xamarin ToolbarItems, you could try update you Xamarin Forms version to see if the issue was fixed.
A workaround would be using a NavigationPage.TitleView (source)
<ContentPage>
<NavigationPage.TitleView>
<StackLayout Orientation="Horizontal" VerticalOptions="End" Spacing="10" HorizontalOptions="End">
<Image Source="cog.png">
</Image>
</StackLayout>
</NavigationPage.TitleView>
</ContentPage>

Xamarin.Forms Popup Dialog with custom view

I am trying to implement Popup dialog or Dialog in Xamarin.Forms but i am unable to find any reference or document to achieve this.
I want to show view on top of current page, something like this...
Currently i am focusing on iOS in Xamarin.Forms... Any code snippet or project reference is appreciated
Popup Page Plugin for Xamarin Forms
The plugin allows you to open any page as a popup.
Nuget: https://www.nuget.org/packages/Rg.Plugins.Popup/
Unfortunately you can't Push to the ModalStack because it replaces the current page and you want to see the current page underneath.
So you have a few options here of create your own if you want complete customization or use a package such as: https://github.com/aritchie/userdialogs. They have a link to examples on that page.
Here is a quick customizable one if you want to roll your own.
<Grid IsVisible={Binding IsDialogShown}" BackgroundColor="Black" Opacity="0.7">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="500" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackLayout Grid.Row="1">
.. Controls in here (change this to grid or whatever you want)
</StackLayout>
</Grid>
You can take a look to popup layout in Xamarin Labs
https://forums.xamarin.com/discussion/32373/how-to-implement-a-pop-up-window-in-xamarin-forms
FormsPopup can do the trick using Xamarin Forms
We can achieve dialog like interface using PopupLayout
https://github.com/XLabs/Xamarin-Forms-Labs/blob/master/src/Forms/XLabs.Forms/Controls/PopupLayout.cs
How to use :
http://forums.xamarin.com/discussion/comment/101489/#Comment_101489

What should be done to fit a webview to the device screen size in wp8.1?

I am developing an application in WP 8.1 which uses the webview control. I tested the app in a 4 inch device and looked fine. but when this app was tested in a bigger device the web view doesn't seem to fit the screen. My xaml code is like
<Grid Margin="0,0.333,0,-1.333" Height="641" VerticalAlignment="Top">
<ProgressBar x:Name="home_progress_bar" IsIndeterminate="True" Visibility="Collapsed" Height="70" Margin="0,282,2,258" Canvas.ZIndex="999999" FontSize="15"/>
<WebView x:Name="orderWebView" HorizontalAlignment="Left" VerticalAlignment="Top" ScriptNotify="orderWebView_ScriptNotify" NavigationStarting="orderWebView_navigation_starting" NavigationFailed="orderWebView_navigation_failed" NavigationCompleted="orderWebView_NavigationCompleted" Height="643" Width="400" DOMContentLoaded="orderWebView_DOMContentLoaded" Margin="0,0,0,-2"/>
</Grid>
<Page.BottomAppBar>
<CommandBar x:Name="Appbar_homepage" Background="{StaticResource PhoneAccentBrush}" ClosedDisplayMode="Minimal" >
<AppBarButton x:Name="AppButton_home" Label="home" Icon="Home" Click="AppButton_home_Click"/>
</CommandBar>
</Page.BottomAppBar>
Please point out what I am missing.
You have hardcoded the width and height of the WebView. Remove the Width and Height properties, change HorizontalAlignment and VerticalAlignment to "Stretch" and optionally play with the Margin property to give it a bit of a margin around.
Example:
<WebView x:Name="orderWebView" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10" />

Data Templated ListBox not stretching Horizontally - again

Can't get my horizontal ListBox with 'Data Template' to stretch fully.
I researched this topic and the most popular answer is to set the ItemContainer Style like :
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListBox.ItemContainerStyle>
This doesn't seem to work for me.
Here is the fully XAML code. The ListBox.ItemsSource = ObservableCollection
<UserControl.Resources>
<ResourceDictionary>
<ItemsPanelTemplate x:Key="ItemsPanel">
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
<DataTemplate x:Key="ItemTemplate">
<Button Margin="-2,-2,-4,-2" >
<StackPanel>
<TextBlock Text="{Binding}"
TextWrapping="Wrap"/>
</StackPanel>
</Button>
</DataTemplate>
</ResourceDictionary>
</UserControl.Resources>
<ListBox VerticalAlignment="Top"
Height="50"
Background="Red"
ItemsPanel="{StaticResource ItemsPanel}"
ItemTemplate="{StaticResource ItemTemplate}"
ItemsSource="{Binding Headers}" >
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
Unfortunately this is difficult to do if you really want to use data-binding with a ListBox (or in fact any ItemsControl).
The reason is that there is no standard panel that works like a StackPanel but stretches its elements in the layout direction.
I don't even know of any third-party panel that does that (which makes me sometimes wonder what it exactly is that toolkit providers are for). I have a small marker in my mind to write one myself next time I need it, because it's easy to do if you're already familiar with developing panels.
If you are not, you are probably better off with creating a Grid programmatically.
I assume you have a variable number of elements (otherwise you could just define each in xaml and wouldn't need a ListBox).
Instead of using a ListBox with data binding you could also programmatically create ToggleButtons in a Grid along with the GridColumns all set to being star-sized.
Of course you could also just change your design and have the buttons be left-justified.
I know that this is a nuisance, but that's how it is.

Resources