I'm using Xamarin.Forms and I haven't found out how to have a multiline label for UWP. In my real project I have the label in a Grid on a ViewCell in a ListView. For the below example I've put it into a StackLayout:
<StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<Label x:Name="titleLabel" Text="some long text" LineBreakMode="WordWrap" />
<Label x:Name="valueLabel" Text="perhaps a much, much, much, much, much, much, much, much, much longer text" LineBreakMode="WordWrap" />
</StackLayout>
The code is working on iOS and Android, but not on UWP. Here the text gets cut off. If only one label and no StackLayout is used it appears correctly on UWP with the multiline text.
I also tried to use a custom renderer with a multiline TextBlock as label, but the result was the same - the text is cut off.
Is this a bug or am I missing something?
Edit:
Now I made a UWP project
<StackPanel Orientation="Horizontal">
<TextBlock Text="oh this is a label" TextWrapping="Wrap" />
<TextBlock Text="and this should be a very, very, very, very, very, very, very, very, very, very long text" TextWrapping="Wrap" />
</StackPanel>
and here the text is also cut off. It seems it isn't possible in UWP. Are there any other solutions/workarounds?
If you set a WidthRequest for each label, the multiline label is correctly displayed (by growing in height).
An alternative solution is e.g. putting the label into a Grid and use a fixed column width.
The reason for that behavior could be that StackLayout has a default width of Auto (if nothing explicitly set) and the label doesn't know how big it could be. If you set a width, the label can grow up to that size.
This post brought me on the idea.
Related
I have a grid with Frame elements as cells. Within some frame elements, there's label elements. The problem is the label stretches only as much as its content.
My goal is to make labels take the entire space of its parent elements(Frames).
I tried setting the VerticalOptions and HorizontalOptions properties to "StartAndExpand" and also "FillAndExpand" to no avail
<Grid>
<Frame Grid.Row="0" Grid.Column="0">
<Label Text="Hello" />
</Frame>
...
</Grid>
Thank you!
EDIT: To clarify, I want to stretch label itself but not its text.
As Frame has a default padding, simply set it manually like below.
<Frame padding="0">
<....>
</Frame>
Plus, sometimes label with long text not behave correctly inside the Frame,
and one workaround is to wrap the Label with a StackLayout.
I created a solution (see code here) from a blank Xamarin Forms template, running the latest stable version of Xamarin Forms. I added the experimental Shapes and SwipeView as required into my native projects, and I have a list of rows just saying "Hello" inside a Collection View.
I attempted to add a semicircle shape to the right swipe item's Grid, so it looks like the row has a rounded edge instead of rectangular shape.
But as you can see in the image below, the Shape just disappears after swiping to the right the second time. And occasionally the shape won't even appear in the row's swipe item.
Please note that the label always displays though, its just the shape going away. Also tested in Android & noticed the same behaviour. Do you know what the issue might be and if there's a work around?
Edit: Posted this and got a response to create an issue. Still looking for a workaround though
You can use Frame with CornerRadius to achieve the result:
<StackLayout Orientation="Horizontal" Padding="0" Margin="0" Spacing="0">
<Label
Text="Left"
HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand" />
<!--<Path HorizontalOptions="EndAndExpand" Fill="White" Stroke="White" Aspect="Fill" Data="m0.19956,-0.20844l14.43749,0l0,0c7.97347,0 14.43748,6.51981 14.43748,14.56254c0,8.04265 -6.464,14.5625 -14.43748,14.5625l-14.43749,0l0,-29.12504z" >
<Path.RenderTransform>
<RotateTransform CenterX="14.637"
CenterY="14.3541"
Angle="180" />
</Path.RenderTransform>
</Path>-->
<Frame BackgroundColor="Yellow" CornerRadius="30" IsClippedToBounds="True" HeightRequest="30" WidthRequest="30" HorizontalOptions="End" Margin="0,0,-51,0">
</Frame>
</StackLayout>
I have a problem making my ImageButton's width fixed and the Height will be changed with the size of the image that I use in the ImageButton, I use the ImageButton multiple times in a Scrollview, I use Visual Studio to create a Cross-Platform App using Xamarin, So what I used to solve my problem are here and here, But I wasn't able to solve it using anything, And this is a picture that describes what I want:-
And please don't make it duplicate if there's answers for my question because I am new to Xamarin Forms And I didn't find any answer exactly to my question, And this is my code:-
<Frame CornerRadius="10" OutlineColor="#fce9cc" Padding="4" Margin="15" VerticalOptions="StartAndExpand"
HasShadow="True" x:Name="ViewLayout" x:FieldModifier="public" BackgroundColor="Black">
<StackLayout>
<Label x:Name="filmNameLabel_1" HorizontalOptions="Center" FontSize="Large" TextColor="White"
Margin="0,15,0,15"/>
<StackLayout Orientation="Vertical">
<ImageButton x:Name="imageWidget_1" BackgroundColor="Black" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Aspect="AspectFill"/>
</StackLayout>
</StackLayout>
</Frame>
First time I set the StackLayout or the parent of the ImageButton's HeightRequest to a number and it would make the ImageButton's Height a fixed number but I dont want that I want the ImageButton's Height to change with the Image's size Ratio bye the width which is fixed next to
the parent layout.
I have decided to try Xamarin Forms, because I thought that I can make one design for all platforms or at least Android and iOS.
However a simple form like:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:app91="clr-namespace:App9;assembly=MasterDetail.Android"
x:Class="MasterDetail.CompetitorsListPage"
>
<StackLayout>
<Label Text="{Binding CurrentEvent.Name}"></Label>
<StackLayout Orientation="Horizontal">
<Button Text="By Place" Clicked="Button_OnClickedByPlace"></Button>
<Button Text="By Number" Clicked="Button_OnClickedByNumber"></Button>
<Button Text="By Rating" Clicked="Button_OnClickedByRating"></Button>
<Button Text="Change Event" Clicked="Button_OnClickedChangeEvent"></Button>
</StackLayout>
<ScrollView>
<ListView x:Name="couples" ItemSelected="Comps_OnItemSelected" ItemTapped="Couples_OnItemTapped">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout Orientation="Horizontal">
<Label Text="{Binding Round}"></Label>
<Label Text="{Binding Pos, StringFormat='({0}).'}"></Label>
<Label Text="{Binding Name}"></Label>
<Label Text="{Binding StartingNumber}" ></Label>
<Label Text="{Binding OldRating, StringFormat=' [{0}]'}"></Label>
<!--<Label Text="{Binding NewRating, StringFormat=' {0} ]'}"></Label>-->
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ScrollView>
</StackLayout>
</ContentPage>
Looks completely different on Android and iOS. I do not mind colours, but font size? I do not set font anywhere in the code or xaml.
Any idea what am I doing wrong?
Here it is a picture showing both versions:
This is by design. Forms is intended to provide a native experience on each platform by using their respective UI standards. Android has a different default color scheme than iOS. iOS default buttons look different than Android.
You can override the default fonts, sizes, colors, etc if you like in order to provide a more consistent UI. Xamarin has also introduced Themes for Forms which help you provide a consistent UI between platforms.
Because Android has variety of screen sizes and different screen DPI as compared to standard dpi and font sizes across iOS devices, it is not possible to create same look. But you can certainly change Theme in the MainActivity of your Droid project and increase font size as per your convenience. Beware that your theme's font size may be too big for small devices and too small for big devices. You can add scaling factor for font size in your theme, but I have not been very successful, instead, I tried to design a UI that will automatically fit for the best.
As per Xamarin Evolve 2016, some questions were raised regarding font sizes, they said it is difficult, but they are trying to make some unified font sizing.
Although Xamarin.Forms has everything in Xaml and C#, you still need to use iOS assets and Android resources to customize look and feel.
For me, #Jason's answer and comments from #Egg and #Bill Reiss are spot-on.
Meanwhile, so often clients request "same font size" across platforms that something like this finds its way into base Styles or Theme to account for what seems to be "natively smaller" fonts on Android:
<OnPlatform x:TypeArguments="Font">
<OnPlatform.iOS>Bold,Medium</OnPlatform.iOS>
<OnPlatform.Android>Bold,Large</OnPlatform.Android>
<OnPlatform.WinPhone>Bold,Medium</OnPlatform.WinPhone>
</OnPlatform>
Something similar can also be expressed in code at or near app startup, for example as a base Label font added to global Styles dictionary.
Just wanted to give a concrete example of what others above alluded to.
Strange behavior on iOS - as you can see those are labels in StackLayout, while in Android they behave OK, in iOS second and third label behave more lithe they were in some kind of grid rather than stack –
You have put 5 labels in a horizontal stack, and haven't changed the layout options on any of them. This will 'stack' all 5 labels next to each other, then size them based on the amount of text to be displayed. There is not enough horizontal space to accommodate all of the text, so the labels are wrapping vertically. The longest labels show the most wrapping, but as they get longer other labels wrap as well, which is why the Pos and OldRating data raps in some labels. When I'm working out layouts like this I often add different background colors to each control so I can see how they are laying out.
There are different ways to solve this depending on your desired result. If you want the entire line of text to wrap you can concatenate the data behind the scenes and add it as one label. If you want the name to wrap and the other data to display without wrapping you can set WidthRequests on the labels.
I am trying to change the size of the PanoramaItem's title, but it doesnt work. I tried the FontSize attribute, but it does nothing. I could change the font size of the Panorama's title using this code:
<controls:Panorama.TitleTemplate>
<DataTemplate>
<TextBlock Text="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}" FontSize="100" Margin="0,50,0,0" />
</DataTemplate>
</controls:Panorama.TitleTemplate>
Try setting Panorama.HeaderTemplate instead of TitleTemplate
It usually helps to open controls in Expression Blend when trying to style them for the first time, It makes it very easy to see all the different templates involved and their default values.