I have added an icon to the toolbar by the following code, but how can I align it to center. Now it is on the right end. In this thread telling it is not possible in xamarin forms.
<ContentPage.ToolbarItems>
<ToolbarItem Icon="logo-final.jpg"/>
</ContentPage.ToolbarItems>
I need the icon on the center like below screen.
Please suggest a solution for this feature?
You should try Navigation Title view
<ContentPage>
<NavigationPage.TitleView>
<StackLayout Orientation="Horizontal" VerticalOptions="Center" Spacing="10">
<Image Source="iconXamagon.png">
</Image>
</StackLayout>
</NavigationPage.TitleView>
...
</ContentPage>
For more referance https://montemagno.com/xamarin-forms-icons-in-navigation-toolbar/
Related
is it possible to round the corners of the XCT popup?
I tried to set the BackgroundColor to transparent, and to set the body in a frame with the option CornerRadius - but this does not work as desired.
Does anyone have a tip on how to round the corners?
<xct:Popup xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="CashTracker.Views.ImagePopup"
xmlns:viewmodels="clr-namespace:CashTracker.ViewModels"
xmlns:xct="clr-namespace:Xamarin.CommunityToolkit.UI.Views;assembly=Xamarin.CommunityToolkit"
Size="300,400"
BackgroundColor="Transparent">
<Frame CornerRadius="20" HasShadow="True">
<StackLayout>
<Label Text="Aufgenommenes Foto" FontSize="Medium" HorizontalOptions="Center"/>
<Image x:Name="PopupImageSource"/>
</StackLayout>
</Frame>
</xct:Popup>
Xamarin XCT Popup
The popup should look like this - only without the white corners.
Xamarin Popup Frame
Somehow BackgroundColor was not working for Popup. Hence use the Color propperty for setting color of the Popup.
If you are using Frame in your layout, you can use Frame's CornerRadius for rounded corners (only if you are using Frame).
If you are not using Frame then you can use Xamarin Community Toolkit's CornerRadiusEffect.CornerRadius to set CornerRadius for any Layout, View or Control.
Hence for your question, it can be done by setting Popup's color as Transparent and your content's parent element must have property for corner radius and must have BackgroundColor set to White or any other Color as your Popup`s color is Transparent.
Here's the XAML
<xct:Popup ...
xmlns:xct="clr-namespace:Xamarin.CommunityToolkit.UI.Views;assembly=Xamarin.CommunityToolkit"
Size="300,400"
Color="Transparent">
<Frame CornerRadius="20" HasShadow="True">
<StackLayout>
<Label Text="Aufgenommenes Foto" FontSize="Medium" HorizontalOptions="Center"/>
</StackLayout>
</Frame>
//OR, if you don't need Frame then,
<StackLayout BackgroundColor="White" xct:CornerRadiusEffect.CornerRadius="10">
<Label Text="Aufgenommenes Foto" FontSize="Medium" HorizontalOptions="Center"/>
</StackLayout>
</xct:Popup>
There are lot of bugs in Xamarin Community Toolkit controls and views, we need to have some work-around for every control. Be it XCT's Popup, TabView, or extensions such as CornerRadius, ShadowEffect, TouchEffects, NativeAnimations, etc. The Community can't provide a single control without any bugs. But still, there are lots of useful features in XCT, hence we can only hope that the bugs are fixed, although the focus of fixing bugs if moved on to MAUI's Community Toolkit, until then we can use some work-arounds till stable and useful version of MAUI is released (considering its current status while writing this answer).
I am building this view currently:
This is a snapshot of the ios render, the code simply is:
<StackLayout>
<Image Source="img_logo"/>
</StackLayout>
But Android is not quite the same:
I tried everything, giving it verticaloptions, horizontaloptions, changing the aspect to everything, the image is never displayed as it is in ios. It is either clipped, or loses its original aspect ratio. I dont know what else to try here and why I have to do anything in the first place. Please tell me the atributes I need to use...
This code is expected to be rendered differently in some cases.
It is very important what is the target screen density of the image in your platform project. If it is different then obviously it will be rendered at a different size with the code above.
If you want to achieve the same look set the Width or Height property or both. Assuming that the container allows those values (that it is big enough) it will look exactly the same then.
If you want to adjust adjust the size of the image according to the space ratio of different views on the page, you can use Grid to achieve this.
You can set the width to Star or a special value.
For more about this, you can check rows-and-columns.
You can refer to the following code:
<ContentPage.Content>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="200" />
</Grid.RowDefinitions>
<!-- Logo -->
<Image Grid.Row="0"
Source="test.png"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
/>
<!-- Sign In Button -->
<StackLayout Grid.Row="1" Padding="10,0,10,0" VerticalOptions="Center">
<Button VerticalOptions="Center" Text="Sign In " />
</StackLayout>
</Grid>
</ContentPage.Content>
In my Xamarin Forms app I have a simple ListView, bound to a collection. Each collection item consists of two strings that I display in Labels. The strings may not fit on one line, in which case they should wrap and take multiple lines.
I cut down the code to the bare minimum to post here:
<ScrollView Orientation="Vertical">
<ListView x:Name="lv" ItemsSource="{Binding MessageItems}" HasUnevenRows="True" Margin="10,10,30,10">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Frame VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" HasShadow="True" BorderColor="#0A2966" Margin="10,10,10,10">
<StackLayout Orientation="Vertical" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<Label x:Name="ShortText" LineBreakMode="NoWrap" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
Short Text
</Label>
<Label x:Name="LongText" LineBreakMode="WordWrap" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Text="{Binding MessageText}">
This is a long message. It is so long it is going to wrap to the next line. It goes on and on and on to demonstrate word wrapping.
</Label>
</StackLayout>
</Frame>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ScrollView>
This all works as expected in UWP:
But in WPF, it just displays each label on one line, cutting off the text if it does not fit:
I have specified LineBreakMode="WordWrap" in XAML, even though it's the default value, but the text still does not wrap.
There appears to be multiple discussions of labels not wrapping in Xamarin forums, for example this one https://forums.xamarin.com/discussion/79278/word-wrap-on-label-doesnt-appear-to-be-working, but they didn't provide and answer for me.
There is a bug on Github that seems to describe exactly my issue (https://github.com/xamarin/Xamarin.Forms/issues/3558), but it was marked resolved and the fix has been merged a while back. I assume it would already be incorporated in the latest release of Xamarin Forms, but I am not sure how to check.
I am using Xamarin Forms 4.8.0.1534 (the latest version), and I also tried several different 4.8.x and 4.7.x builds without success.
The culprit here is the <Frame> element. I determined this by simplifying your sample code, removing one part or another. Placing <StackLayout> directly inside <ViewCell> (without the intervening <Frame>) fixes the layout and makes Label text wrap as it's supposed to.
Of course, if you do this, you also lose the nice visual border around your labels. Not to worry. We can draw another border and give it the right size and position, so that it looks like it wraps your content. The trick here is to use a Grid and place both the <Frame> and the <StackLayout> into Grid row 0 column 0.
After the above two changes we end up with this:
<ScrollView Orientation="Vertical">
<ListView x:Name="lv" ItemsSource="{Binding MessageItems}" HasUnevenRows="True" Margin="10,10,30,10">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Margin="10,10,10,10">
<Frame VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" HasShadow="True" BorderColor="#0A2966"/>
<StackLayout Orientation="Vertical" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Margin="20">
<Label x:Name="ShortText" LineBreakMode="NoWrap" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
Short Text
</Label>
<Label x:Name="LongText" LineBreakMode="WordWrap" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Text="{Binding MessageText}">
This is a long message. It is so long it is going to wrap to the next line. It goes on and on and on.
</Label>
</StackLayout>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ScrollView>
Now Labels wrap as expected in both WPF and UWP and the border still shows.
XF WPF is still in BETA ... there are many others issues concerning Labels like spans fontsize ....
Regarding your issue, I guess it is the ListView control. Its development has stopped and Microsoft actively recommends CollectionView or BindableLayout.
I have the need for a scrollview on top of a background image. I found a number of recommendations to use a , making the image the first element. What I end up with is:
<ContentPage>
<ContentPage.Content>
<RelativeLayout Padding="0">
<Image Aspect="AspectFill" Source="Background" />
<ScrollView>
<!-- Various components -->
</ScrollView>
</RelativeLayout>
</ContentPage.Content>
</ContentPage>
Using the above, I get a screen that looks correct, but the ScrollView doesn't scroll.
Am I missing something? Or does anyone have an alternative to the layout above? The background needs to be fixed and not scroll with the other elements on "top" of it.
It turns out there is a way to do this such that the two main requirements (fixed background, scrollable elements) are met.
Instead of using RelativeLayout, use a Grid. The following layout works as needed...
<ContentPage>
<ContentPage.Content>
<!-- Use a Grid, rather than a RelativeLayout -->
<Grid Padding="0">
<Image Aspect="AspectFill" Source="Background" />
<ScrollView>
<!-- Various components -->
</ScrollView>
</Grid>
</ContentPage.Content>
</ContentPage>
I want to add draggable icon in mobile app which i can move anywhere on screen.
I tried with floating action but no luck.
<views:FloatingActionButton HorizontalOptions="End" VerticalOptions="End"
ImageSource="CallHistory.png"
x:Name="floCallHistory"
ButtonColor="Transparent"
Clicked="floCallHistory_Clicked" BackgroundColor="Transparent" FlowDirection="LeftToRight"
>
</views:FloatingActionButton>