How can I allocate more space to a numeric - xamarin

Here is the XAML code that I created:
<ViewCell>
<Grid VerticalOptions="CenterAndExpand" Padding="20, 0">
<Label HorizontalOptions="StartAndExpand" Text="ABC" />
<Entry Keyboard="Numeric" VerticalOptions="Center" HorizontalOptions="End" />
</Grid>
</ViewCell>
When I run the code the data entry area for the window is only wide enough to show one digit. Is there a way I can expand this so it will allow me to enter three digits?

Set a WidthRequest value, and also try changing the HorizontalOptions
<Entry Keyboard="Numeric" VerticalOptions="Center" WidthRequest="100" HorizontalOptions="FillAndExpand" />

Related

How to make Grid Row dynamic in CollectionView control of .Net MAUI?

I'm trying to achieve dynamic row height in CollectionView control, so that when ever I have more text for a particular property it will extend the height of the frame automatically.
I have tried with ListView as well using HasUnEvenRow property "true" but with that also it's not working.
Here is my code:
<StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<Grid RowDefinitions="*,60" BackgroundColor="{StaticResource PageBackgroundColor}" Padding="0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<CollectionView Grid.Row="0" HorizontalOptions="Fill" VerticalOptions="Fill"
ItemsSource="{Binding Inspections}"
VerticalScrollBarVisibility="Always"
ItemsLayout="VerticalList" ItemSizingStrategy="MeasureAllItems">
<CollectionView.ItemTemplate>
<DataTemplate>
<Frame Padding="15" HasShadow="False">
<Grid HorizontalOptions="Fill"
VerticalOptions="Fill"
BackgroundColor="White"
RowSpacing="25"
RowDefinitions="Auto,Auto,Auto"
ColumnDefinitions="*,Auto">
<StackLayout
Orientation="Horizontal"
Grid.Row="0"
Grid.Column="0">
<Label Text="{Binding Path=BusinessName}"
Style="{StaticResource LabelTitleStyle}" />
<Grid Padding="15,0,0,0">
<baseChip:Chip
HorizontalOptions="Fill" VerticalOptions="Fill"
Style="{StaticResource ChipContainer}"
HasShadow="False"
BackgroundColor="{Binding Path=ChipBackgroundColor}">
</baseChip:Chip>
<Label
Text="{Binding Path=ChipText}"
Style="{StaticResource ChipLabel}"
HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand"
TextColor="{Binding Path=ChipTextColor}"/>
</Grid>
</StackLayout>
<Image
Grid.Row="0"
Grid.Column="1"
HorizontalOptions="End"
VerticalOptions="Center"
Aspect="AspectFit">
<Image.Source>
<FontImageSource Glyph="{x:Static helper:MaterialFontHelper.FilePdfBox}"
Color="{StaticResource DarkGray}"
Size="20"
FontFamily="MaterialDesignIcons"/>
</Image.Source>
</Image>
<Grid Grid.Row="1"
Grid.Column="0"
Grid.ColumnSpan="2"
RowDefinitions="Auto, Auto"
ColumnDefinitions="*, *">
<Label
Grid.Row="0"
Grid.Column="0"
Text="Inspection Type"
Style="{StaticResource LabelKeyStyle}" />
<Label
Grid.Row="1"
Grid.Column="0"
Text="ksd kahdkahd kahd kahd aojsoiud aasjlj sdlkja dlkja da asdadas alsajdlaksjdlajd alsjdalkjd alksjd sa"
Style="{StaticResource LabelValueStyle}" />
<Label
Grid.Row="0"
Grid.Column="1"
Text="Primary Inspector"
Style="{StaticResource LabelKeyStyle}" />
<Label
Grid.Row="1"
Grid.Column="1"
Style="{StaticResource LabelValueStyle}" >
<Label.FormattedText>
<FormattedString>
<Span Text="{Binding Path=InspectorFirstName}"/>
<Span Text=" "/>
<Span Text="{Binding Path=InspectorLastName}"/>
</FormattedString>
</Label.FormattedText>
</Label>
</Grid>
<Grid Grid.Row="2"
Grid.Column="0"
Grid.ColumnSpan="2"
RowDefinitions="*, *"
ColumnDefinitions="*, *">
<Label
Grid.Row="0"
Grid.Column="0"
Text="Scheduled Date"
Style="{StaticResource LabelKeyStyle}" />
<Label
Grid.Row="1"
Grid.Column="0"
Text="{Binding Path=ScheduledStartDate, Converter={StaticResource dateFormatter},ConverterParameter='long'}"
Style="{StaticResource LabelValueStyle}" />
<Label
Grid.Row="0"
Grid.Column="1"
Text="Completed Date"
Style="{StaticResource LabelKeyStyle}" />
<Label
Grid.Row="1"
Grid.Column="1"
Text="{Binding Path=CompletionDate, Converter={StaticResource dateFormatter},ConverterParameter='long'}"
Style="{StaticResource LabelValueStyle}" />
</Grid>
</Grid>
</Frame>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
<StackLayout
Grid.Row="1"
VerticalOptions="End"
HorizontalOptions="FillAndExpand"
BackgroundColor="{StaticResource White}">
<controlTemplate:BeginInspectionContentView></controlTemplate:BeginInspectionContentView>
</StackLayout>
</Grid>
</StackLayout>
Output & expected output image attached here:
How to achieve dynamic height for this UI? Any help or suggestions are welcome.
There are three solutions to this problem:
You can change CollectionView to FlexLayout with BindableLayout.ItemsSource and BindableLayout.ItemTemplate. Then you don't need to set Height for item or FlexLayout because all are dynamic.
You can set a value to collectionView.HeightRequest using MVVM. When item increase, the height will increase as well. For more details about this solution, you may refer to the link.
You can use CollectionView.Behaviors to calculate the Height of every item to increase the height of ContentView. For more details about this solution, you may refer to the link.
You have Grid. With StackLayout. With Grid. With Small Grids inside it.
I will put aside for now, that this is extremely bad for rendering. (It is serious problem however...)
None of the expected output justify this organization.
If you need for element to occupy 2 columns, you can use columns span 2.
Before anything else, please combine all 4 grids in a single grid.
After you are done with that, limit your VisualElements height, or, even better, limit the content you are putting in them. (Because cut content looks bad. You should be using something like "show more" link, that opens popup or whatever).
If you have any questions, please ask.
Edit: Let me clarify:
You have the same Grid code. Most important part - columns are * , * , and rows are auto height. And every 2 rows, you create another GRID, that is copy of the first GRID.
This is extremely counterproductive.
Also, just because you can do something, and it is "working in xamarin", it doesn't mean that you should do it.
First, put everything in the same grid, instead of nesting it and copying grids, then you can start working on CLIP/Height limit/etc.
(Recommending you to test it on IOS, because once you get it running fine there, it is much easier to fine-tune it for other platforms, than the other way around.)

Why only the second Frame shows in a StackLayout

I have a Stacklayout that contains another Stacklayout and an Image. In order to have rounded corners for both children of the top Stacklayout, I added Frame for each child. Now, only the second child (Image) appear no matter how I change the visibility of the two children.
<StackLayout HeightRequest="135" WidthRequest="100" Margin="5,5" Grid.Row="0" Spacing="0" HorizontalOptions="Start" VerticalOptions="Start">
<Frame IsVisible="false" CornerRadius="5" IsClippedToBounds="True" Padding="0" HasShadow="False" x:Name="InitialsFrame">
<StackLayout IsVisible="false" HeightRequest="100" WidthRequest="100" BackgroundColor="{Binding Color}">
<Label FontSize="60" Text="{Binding Initials}" TextColor="White" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" MaxLines="1" x:Name="InitialsLabel">
</Label>
</StackLayout>
</Frame>
<Frame IsVisible="true" CornerRadius="5" IsClippedToBounds="True" Padding="0" x:Name="ImageFrame">
<Image IsVisible="true" Source="{Binding Image}" HeightRequest="100" WidthRequest="100" x:Name="IconImage" />
</Frame>
</StackLayout>
Without the two Frames, I could choose which child to appear by setting IsVisible to True. But now, setting IsVisible does not work any more. Is there another way to conditionally choose which child to appear?

Xamarin.Forms: can grid cell include several labels?

One of the grid cells looks like this:
<Label Text="{Binding Address1}" FontSize="12" TextColor="Black" Grid.Row="1" Grid.Column="0"/>
This displays Address1 which is correct.
But instead of just showing Address1, I would like to display Address1, City, St, each with a different FontSize.
Can this be done without altering the number of rows and columns in the grid?
One way is to place a StackLayout at the Grid row|column and then separately format each element within it:
<Grid....
~~~
<StackLayout Grid.Row="1" Grid.Column="0">
<Label Text="{Binding Address1}" FontSize="12" TextColor="Black" />
<StackLayout Orientation="Horizontal" >
<Label Text="{Binding City}" FontSize="10" TextColor="Black" />
<Label Text="{Binding St}" FontSize="10" TextColor="Black" />
</StackLayout>
<StackLayout>
~~~
</Grid>
Sure, you would use:
<StackLayout Grid.Row="1" Grid.Column="0">
<Label Text="l1"/>
<Label Text="l2"/>
<Label Text="l3"/>
</StackLayout>
You can use other layouts such as StackLayout inside of your Grid as others suggested but you can also put multiple Views inside a Grid cell by setting the same Grid.Row and Grid.Column for them and by setting HorizontalOptions and VerticalOptions of views inside the Grid you can choose each view position.
For Example:
<Grid....
~~~
<Label Grid.Row="0" Grid.Column="1" HorizontalOptions="Start" VerticalOptions="Start" Text="{Binding Address1}" FontSize="12" TextColor="Black" />
<Label Grid.Row="0" Grid.Column="1" HorizontalOptions="Start" VerticalOptions="End" Text="{Binding City}" FontSize="10" TextColor="Black" />
<Label Grid.Row="0" Grid.Column="1" HorizontalOptions="End" VerticalOptions="End" Text="{Binding St}" FontSize="10" TextColor="Black" />
~~~
</Grid>

TextWrapped Label breaks Layout Option FillAndExpand in StackLayout

I'm having a cell view with nested StackLayouts, there's one label that will be wrapped if the text is long, which is the desired behaviour. However, the wrap breaks the LayoutOptions set to (basically) all parent views resulting in a gray gap on the right hand side.
<StackLayout Orientation="Horizontal" BackgroundColor="Gray" Margin="0,30,0,0">
<BoxView
HorizontalOptions="Start"
BackgroundColor="#EEBB00"
WidthRequest="100"
/>
<StackLayout
BackgroundColor="#CC4400"
HorizontalOptions="FillAndExpand"
>
<BoxView
BackgroundColor="Green"
HeightRequest="10"
HorizontalOptions="FillAndExpand"
/>
<Label
FontSize="16"
HorizontalOptions="FillAndExpand"
Text="Name that is toolongandwillbewrapped"
/>
<StackLayout
Orientation="Horizontal"
HorizontalOptions="FillAndExpand"
BackgroundColor="Blue"
>
<Label
FontSize="13"
Text="Left"
TextColor="White"
HorizontalOptions="StartAndExpand"
VerticalTextAlignment="End"
/>
<Label
FontSize="13"
Text="Right"
TextColor="White"
HorizontalOptions="EndAndExpand"
VerticalTextAlignment="End"
/>
</StackLayout>
</StackLayout>
</StackLayout>
The resulting views are:
So I can tell why this is happening, but well, of course I don't like it. The expected behaviour is for the right-hand-side stacklayout to expand all the way to the right. I've tried various ways to circumvent this and would not be here if I had succeeded. Does anybody have an idea?
Unfortunately, it's a bug in Xamarin.Forms (probably, iOS-only).
Bugzilla #28650
Bugzilla #31128
Bugzilla #33841
The workaround in that case is using Grid instead of StackLayout : http://forums.xamarin.com/discussion/comment/152969/#Comment_152969

Entry Component Fill the Screen on Xamarin Forms

I need to make Entry and Picker fields fill the screen horizontally.
I have tried any possible HorizontalOptions but no success.
My code is as follows;
<StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand">
<StackLayout Orientation="Vertical">
<Entry x:Name="ReceiverIBANTextField" Placeholder="Alıcı IBAN" Keyboard="Numeric"> </Entry>
<Entry x:Name="ReceiverFullNameTextField" Placeholder="Alıcı Ad Soyad" > </Entry>
<StackLayout Orientation="Horizontal">
<Entry x:Name="EntryTransferAmount" Placeholder="Tutar Giriniz" Keyboard="Numeric" VerticalOptions="FillAndExpand"/>
<Label x:Name="LabelCurrencyName" Text="$" />
</StackLayout>
<StackLayout Orientation="Horizontal">
<StackLayout HorizontalOptions="FillAndExpand">
<Label TextColor="#0099DC">Tümünü Aktar </Label>
</StackLayout>
<StackLayout HorizontalOptions="Fill" >
<Switch x:Name="SwitchForAllInForVirman" Toggled="SwitchForAllIn_Toggled" HorizontalOptions="End"/>
</StackLayout>
</StackLayout>
<StackLayout Orientation="Vertical" HorizontalOptions="FillAndExpand" >
<Entry x:Name="EntryDescriptionForVirman" Placeholder="Açıklama Giriniz"></Entry>
<Picker x:Name="PickerPaymentType" Title="Ödeme Tipi" ></Picker>
<Entry x:Name="QuickTransactionNameTextField" Placeholder="Hızlı İşlem Adı"></Entry>
</StackLayout>
</StackLayout>
</StackLayout>
I tried your code in a sample project and you need to also set the HorizontalOptions for the second StackLayout to FillAndExpand for it to work.

Resources