Syncfusion MAUI DataGrid and VerticalStackLayout - maui

I would like to add label above Syncfusion Datagrid but the label is hidden when I run the app in the following page.
See the following repos for complete app.
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="DataGrid.Views.OrderInfoRepositoryView"
xmlns:syncfusion="clr-namespace:Syncfusion.Maui.DataGrid;assembly=Syncfusion.Maui.DataGrid"
xmlns:local="clr-namespace:DataGrid"
Title="Order Info Repository View">
<ContentPage.BindingContext>
<local:OrderInfoRepositoryViewModel x:Name="viewModel" />
</ContentPage.BindingContext>
<ContentPage.Content>
<VerticalStackLayout Margin="20"
Spacing="10">
<Label Text="OrderInfo"
Margin="10,10,10,10"
TextColor="White"
BackgroundColor="Red"/>
<syncfusion:SfDataGrid x:Name="dataGrid"
ItemsSource="{Binding OrderInfoCollection}">
</syncfusion:SfDataGrid>
</VerticalStackLayout>
</ContentPage.Content>
Did try the following but same result.
<Label Text="OrderInfo"
Margin="10,10,10,10"
TextColor="White"
BackgroundColor="Red"/>
<syncfusion:SfDataGrid x:Name="dataGrid"
ItemsSource="{Binding OrderInfoCollection}">
</syncfusion:SfDataGrid>
</VerticalStackLayout>
Here Android screenshot
Added LineHeight and fontSize. No change
Tested with HeightRequest. No change.

It appears that you have set the Content for the ContentPage as DataGrid in OrderInfoRepositoryView.xaml.cs file. Please refer to the below file,
https://github.com/JeanMarcFlamand/MauiSyncFusionExamples/blob/master/DataGrid/Views/OrderInfoRepositoryView.xaml.cs#L12
You are adding the DataGrid as the content of the page in code behind i.e., OrderInfoRepositoryView constructor. That’s why the DataGrid alone is displaying without Label. We request that you remove the codes inside the OrderInfoRepositoryView constructor to overcome the issue.

Related

Setting size of editor for chat UI in .NET MAUI app

In my .NET MAUI app, I'm implementing chat feature and want to make sure that the Editor and Button are perfectly located at the bottom of the screen.
I created a Grid for the controls to produce this layout
The problem I'm having is with the Editor width because if I get it to look right on Android, it's not perfect on iOS and vice versa.
Here's how I approached it:
<Grid
RowDefinitions="50"
ColumnDefinitions="*,50"
RowSpacing="0"
ColumnSpacing="5"
HorizontalOptions="StartAndExpand"
Margin="5,5,5,5">
<Editor
Grid.Column="0" />
<Button
Grid.Column="1" />
</Grid>
Other than entering some arbitrary number for WidthRequest for the Editor, how do I set the width for it so that it always takes up all the available space and look like it in the picture?
After setting HorizontalOptions="FillAndExpand" as Jason suggested like below, it looks right on Android and iOS.
<Grid
RowDefinitions="50"
ColumnDefinitions="*,50"
RowSpacing="0"
ColumnSpacing="5"
HorizontalOptions="FillAndExpand"
Margin="5">
<Editor
Grid.Column="0" />
<Button
Grid.Column="1" />
</Grid>

How can I add an extra label/slide button to a FlyoutItem in MAUI?

I encountered an UI issue when developing an app using MAUI flyoutItem. According to the official doc, it looks like I can only define the flyoutItem appearance by setting two columns(https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/shell/flyout?view=net-maui-7.0): one bind to FlyoutIcon and the other bind to Title.
What if I want to add a third item such as a label for identity/status or a slide button to enable/disable? I expect sth look like this:
[column 0]FlyoutIcon [column 1]Label1 [column 2]Label2/Slide Button
Can you please also show me some sample code for the solution?
Best and Regards
I tried to modify the Grid to add a third column and addition Label but seems not working.
<Shell ...>
...
<Shell.ItemTemplate>
<DataTemplate>
<Grid ColumnDefinitions="0.2*,0.4*,0.4*">
<Image Source="{Binding FlyoutIcon}"
Margin="5"
HeightRequest="45" />
<Label Grid.Column="1"
Text="{Binding Title}"
FontAttributes="Italic"
VerticalTextAlignment="Center" />
<Label Grid.Column="2"
Text="{Binding Text}"
FontAttributes="Italic"
VerticalTextAlignment="End" />
</Grid>
</DataTemplate>
</Shell.ItemTemplate>
</Shell>
Er, guys. Looks like using Menu Item instead of FlyoutItem will resolve the issue.

AbsoluteLayout proportional position flag not working properly in .net MAUI

I'm trying to position a StackLayout to the bottom of the page using an AbsoluteLayout as demonstrated in below code sample. However the position flag is treated as absolute value not proportional resulting in having the StackLayout positioned in the top of the page (rather in the bottom). When I inclemently increase the position value, the StackLayout starts to shift downward which it should not since the the layoutFlags are set to "All". Any help would be appreciated in help to resolve this issue, is it a bug in .net MAUI?
<AbsoluteLayout Margin="5">
<StackLayout BackgroundColor="White"
AbsoluteLayout.LayoutBounds="0,1,1,0.2"
AbsoluteLayout.LayoutFlags="All">
<StackLayout Orientation="Horizontal" HorizontalOptions="Center">
<Label Text="التاريخ المحدد:"/>
<Label x:Name="selectedDeliveryDate"/>
</StackLayout>
<Button x:Name="confirmDateSelected" Text="تأكيد" BackgroundColor="#009688" Margin="20,5,20,5" Clicked="confirmDateSelected_Clicked"/>
</StackLayout>
</AbsoluteLayout>
It works for me.
The problem is something you don't show:
What did you place <AbsoluteLayout ... inside of?
The proportions of AbsoluteLayout are relative to whatever layout it is inside of.
Here I've taken your code, but changed background color to "Red", and placed it directly inside a page:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MauiApp7t.Page3"
Title="Page3">
<AbsoluteLayout Margin="5">
<StackLayout BackgroundColor="Red"
AbsoluteLayout.LayoutBounds="0,1,1,0.2"
AbsoluteLayout.LayoutFlags="All">
<StackLayout Orientation="Horizontal" HorizontalOptions="Center">
<Label Text="التاريخ المحدد:"/>
<Label x:Name="selectedDeliveryDate"/>
</StackLayout>
</StackLayout>
</AbsoluteLayout>
</ContentPage>
This does what you describe: My "red" area is at bottom of screen:
Tested on both Windows and Android.
Tested both as a stand-alone page, and as a page within AppShell.

RefreshView is pushing content to right in .NET MAUI app

Came across this strange behavior in .NET MAUI app while testing it on an iOS device.
First, everything looks fine on Android -- both emaulator and physical device. I then noticed this issue in iOS Simulator and have the same results on my iPhone.
If I have no RefreshView around my CollectionView, the empty view message display where it's supposed -- well almost because I can never place it in the center of the page vertically but other than that, it displays correctly -- see below:
If I do place my CollectionView within a RefreshView, the Label gets pushed to the right -- see below:
Here's the actual code with the RefreshView. All you need to do is remove RefreshView and label is displayed in the center.
<RefreshView
IsRefreshing="{Binding IsRefreshing}"
Command="{Binding RefreshCouponsCommand}">
<CollectionView
x:Name="MyCouponsList"
ItemsSource="{Binding Feed}"
BackgroundColor="Transparent"
VerticalOptions="StartAndExpand"
Margin="0,5,0,0">
<CollectionView.EmptyView>
<VerticalStackLayout
VerticalOptions="CenterAndExpand">
<Label
Text="No data..."
TextColor="{StaticResource Gray600}"
HorizontalTextAlignment="Center" />
</VerticalStackLayout>
</CollectionView.EmptyView>
</CollectionView>
</RefreshView>
Any idea what could be causing this?
try replacing
<CollectionView
x:Name="MyCouponsList"
ItemsSource="{Binding Feed}"
BackgroundColor="Transparent"
VerticalOptions="StartAndExpand"
Margin="0,5,0,0">
<CollectionView.EmptyView>
<VerticalStackLayout
VerticalOptions="CenterAndExpand">
<Label
Text="No data..."
TextColor="{StaticResource Gray600}"
HorizontalTextAlignment="Center" />
</VerticalStackLayout>
</CollectionView.EmptyView>
</CollectionView>
with
<CollectionView
x:Name="MyCouponsList"
ItemsSource="{Binding Feed}"
BackgroundColor="Transparent"
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand"
Margin="0,5,0,0"
EmptyView="No Data..."/>
</CollectionView>

Why Prism's Master Detail Page structure is different from Xamarin.Forms?

I developed one app about months ago with Prism. It's great tool that make perfect structure for my app.
However, today I tried to pick up that app and fix some things that pending for a long time. I used Master Detail page in my app, and today I suddenly found that actually the structure for how I developed this Master Detail page using Prism is kind of out of my knowledge.
So, here it is.
Basically my MasterDetailPage is like this:
<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:b="clr-namespace:Prism.Behaviors;assembly=Prism.Forms"
mc:Ignorable="d"
x:Class="JapaneseLearnPrism.Views.MenuPage">
<MasterDetailPage.Master>
<NavigationPage Title="Menu" Icon="ic_hamburger.png">
<x:Arguments>
<ContentPage Title="{Binding Title}">
<ListView ItemsSource="{Binding MenuItems}"
SelectedItem="{Binding SelectedMenuItem, Mode=TwoWay}"
SeparatorColor="LightGray"
RowHeight="60"
SeparatorVisibility="Default"
BackgroundColor="#e8e8e8">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout VerticalOptions="FillAndExpand"
Orientation="Horizontal"
Padding="20,10,0,10"
Spacing="20">
<Label Text="{Binding PageIconText}" FontFamily="{StaticResource FontAwesomeSolid}" FontSize="Medium" VerticalOptions="Center" />
<Label Text="{Binding Title}" FontSize="Medium" VerticalOptions="Center" TextColor="Black" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.Behaviors>
<b:EventToCommandBehavior EventName="ItemTapped" Command="{Binding NavigateCommand}" />
</ListView.Behaviors>
</ListView>
</ContentPage>
</x:Arguments>
</NavigationPage>
</MasterDetailPage.Master>
</MasterDetailPage>
And the navigation path is this in App.xaml.cs file.
await NavigationService.NavigateAsync(nameof(MenuPage) + "/" + nameof(NavigationPage) + "/" + nameof(Views.MainPage));
But if I look at lots of the Xamarin.Forms samples, the MasterDetailPage is actually different.
They are going to do like below:
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MasterDetailPageNavigation;assembly=MasterDetailPageNavigation"
x:Class="MasterDetailPageNavigation.MainPage">
<MasterDetailPage.Master>
<local:MasterPage x:Name="masterPage" />
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<NavigationPage>
<x:Arguments>
<local:ContactsPage />
</x:Arguments>
</NavigationPage>
</MasterDetailPage.Detail>
</MasterDetailPage>
And that's from Microsoft's official website. The Master Page in above is actually just one ContentPage, however, the Detail page should be NavigationPage, that one I can understand because it makes sense.
However, in my Prism app, the MasterPage also has to be a NavigaionPage, why is that? Any one can help on this?
Thanks.
You can take a look at this wonderfull blog about How to make Master-Detail Page Navigation menu in Xamarin Forms with Prism.
If you scroll down to the bottom of the post, you will see some description on why it works this way, Quoting:
Note: Navigation in Prism is all based on this url format where we can define to which pages we want to go, and it can be something like this: ViewA/ViewB/ViewC/ViewD
... and if you remember we are inside of MasterDetail page so navigating from MasterDetail will get result that those pages will go to Detail part of it... and that is great for us, we have menu in side of master page and choosing menu items will open pages as Detail pages.
The way that Prism Navigation is designed, it makes sense that a DetaiPage goes inside the MasterDetail, so basically it keeps the Prism Logic of doing the Navigation.
Quoting the Basics of Prism Navigation
Navigating in a Prism application is conceptually different than standard navigation in Xamarin.Forms. While Xamarin.Forms navigation relies on a Page class instance to navigate, Prism removes all dependencies on Page types to achieve loosely coupled navigation from within a ViewModel. In Prism, the concept of navigating to a View or navigating to a ViewModel does not exist. Instead, you simply navigate to an experience, or a unique identifier, which represents the target view you wish to navigate to in your application.