Having trouble with using a font. Works fine when I to the following down below.
FontFamily="{StaticResource IconFonts}" Text=""
But it doesn't work if I try to dynamically bind the text property.
FontFamily="{StaticResource IconFonts}" Text="{Binding Comments}"
It shows up all weird. It looks like it tries to do something but doesn't completely render. Here is the full code with my testing included down below. Thanks in advance.
<FlexLayout x:Name="FlexFood"
Wrap="Wrap"
Direction="Row"
JustifyContent="Start"
Padding="0, 10"
BindableLayout.ItemsSource="{Binding FoodCollection}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<StackLayout Padding="5, 0">
<Frame.GestureRecognizers>
<TapGestureRecognizer Tapped="OnTypesSelected"></TapGestureRecognizer>
</Frame.GestureRecognizers>
<Frame.Content>
<StackLayout x:Name="LayoutFood">
<StackLayout VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand">
<Label x:Name="LabelTitle" Padding="0, 10">
<Label.FormattedText>
<FormattedString>
<Span FontSize="Subtitle" Text="{Binding Title}" FontAttributes="Bold"></Span>
<Span Text=" "></Span>
<Span FontSize="Subtitle" Text="{Binding Version}" FontAttributes="Bold"></Span>
</FormattedString>
</Label.FormattedText>
</Label>
</StackLayout>
<StackLayout Orientation="Horizontal">
<StackLayout HorizontalOptions="StartAndExpand">
<Label Text="{Binding Description}" FontSize="Body"></Label>-->
<Label FontSize="Caption" TextColor="#LELELE">
<Label.FormattedText>
<FormattedString>
<Span Text="{Binding fDepartment}"></Span>
<Span Text="{Binding pType}"></Span>
</FormattedString>
</Label.FormattedText>
</Label>
</StackLayout>
<StackLayout HorizontalOptions="End">
<Label Text="{Binding Comments}"></Label>
<Label FontFamily="{StaticResource IconFonts}" Text=""></Label>
<Label x:Name="LabelTypeTest" FontFamily="{StaticResource IconFonts}"
Text="{Binding Comments, StringFormat=''}"></Label>
<Label FontFamily="{StaticResource IconFonts}" Text="{Binding Comments}"></Label>
<Image x:Name="ImageTypeTest">
<Image.Source>
<FontImageSource Size="48" FontFamily="{StaticResource IconFonts}" Color="#000000"></FontImageSource>
</Image.Source>
</Image>
</StackLayout>
</StackLayout>
</StackLayout>
</Frame.Content>
</helper:LayoutGradient>
</StackLayout>
</DataTemplate>
</BindableLayout.ItemTemplate>
</FlexLayout>
Here is the static resource in app
<ResourceDictionary>
<OnPlatform x:Key="IconFonts" x:TypeArguments="x:String">
<On Platform="iOS" Value="Material Design Icons"></On>
<On Platform="Android" Value="IconFonts.ttf#Material Design Icons"></On>
<On Platform="UWP" Value="/Assets/IconFonts.ttf#Material Design Icons"></On>
</OnPlatform>
</ResourceDictionary>
You should return the escape sequence of \uf139 from your binding instead of
You can read the Access from Bindings and Access Directly in XAML section in the source link for more information.
Refer: xamarin-forms-fontawesome-doesnt-work-with-bound-properties
Related
I'm learning xamarin and all my attempts to influence the behavior of my label have failed. only my label still behaves strangely how to right align screen.
They do not change even if I put horizontalOptions everywhere, it seems to me that I just don’t know something
my ProductCard
<Grid xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:models="clr-namespace:Notes.Models;assembly=Notes"
x:DataType="models:Goods"
x:Class="Notes.Cells.ProductCard">
<Frame Style="{StaticResource ProductCard}" BackgroundColor="Coral">
<StackLayout Orientation="Horizontal">
<StackLayout VerticalOptions="Center">
<Label
BackgroundColor="Aqua"
HorizontalTextAlignment="End"
VerticalOptions="End"
HorizontalOptions="End">
<Label.FormattedText>
<FormattedString>
<Span Text="{Binding Name}" Style="{StaticResource LabelMedium}" BackgroundColor="Blue"></Span>
<Span Text=" " BackgroundColor ="Brown"/>
<Span Text="Price: " BackgroundColor="Green"/>
<Span Text="{Binding Price}" FontAttributes="Bold" BackgroundColor="Yellow"/>
</FormattedString>
</Label.FormattedText>
</Label>
</StackLayout>
</StackLayout>
</Frame>
and my ListView
<?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:viewmodels="clr-namespace:Notes.ViewModel"
xmlns:cells="clr-namespace:Notes.Cells"
xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
x:DataType="viewmodels:GoodsViewModel"
x:Class="Notes.Views.ProductsCatalog"
>
<ContentPage.BindingContext>
<viewmodels:GoodsViewModel />
</ContentPage.BindingContext>
<ContentPage.Resources>
<ResourceDictionary>
<DataTemplate x:Key="Normal">
<ViewCell>
<cells:ProductCard/>
</ViewCell>
</DataTemplate>
<DataTemplate x:Key="Special">
<ViewCell>
<cells:SpecialItem/>
</ViewCell>
</DataTemplate>
<cells:ItemDataTemplateSelector x:Key="GoodsSelector"
Normal="{StaticResource Normal}"
Special="{StaticResource Special}"/>
</ResourceDictionary>
</ContentPage.Resources>
<ListView
SeparatorVisibility="Default"
CachingStrategy="RecycleElement"
Style="{StaticResource NoteNewsListView}"
GroupDisplayBinding="{Binding Key}"
IsGroupingEnabled="True"
IsRefreshing="{Binding IsBusy, Mode=OneWay}"
SelectedItem="{Binding CurrentGoods, Mode=TwoWay}"
ItemsSource="{Binding GoodsGroup}"
RefreshCommand="{Binding RefreshCommand}"
ItemTemplate="{StaticResource GoodsSelector}">
<ListView.Behaviors>
<xct:EventToCommandBehavior
Command="{Binding SelectedCommand}"
EventName="ItemSelected" />
</ListView.Behaviors>
<ListView.GroupHeaderTemplate>
<DataTemplate x:DataType="{x:Null}">
<ViewCell>
<StackLayout Padding="0,0,0,0" Margin="10,0,0,0">
<Label Style="{StaticResource LabelLarge}" Text="{Binding Key}" />
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.GroupHeaderTemplate>
<ListView.Header>
<StackLayout Orientation="Horizontal">
<Label
Margin="80"
FontFamily="AC"
HorizontalOptions="Center"
Style="{StaticResource LabelLarge}"
Text="Catalog Products">
</Label>
</StackLayout>
</ListView.Header>
<ListView.Footer>
<StackLayout HorizontalOptions="Center" Orientation="Horizontal">
<Button
Command="{Binding LoadMoreCommand}"
Style="{StaticResource ButtonOutline}"
Text="Load more" />
</StackLayout>
</ListView.Footer>
</ListView>
and my styles
<Style x:Key="ServiceCard" TargetType="Frame">
<Setter Property="HasShadow"
Value="{OnPlatform Android=true, iOS=false, Default=true}"/>
<Setter Property="CornerRadius" Value="20"/>
<Setter Property="BackgroundColor"
Value="{AppThemeBinding Dark={StaticResource CardBackgroundDark},
Light={StaticResource CardBackground}}"/>
</Style>
<Style x:Key="NoteNewsListView" TargetType="ListView">
<Setter Property="HasUnevenRows" Value="True"/>
<Setter Property="BackgroundColor" Value="Transparent"/>
<Setter Property="SeparatorVisibility"
Value="None"/>
<Setter Property="RefreshControlColor"
Value="{StaticResource SystemBlue}"/>
<Setter Property="IsPullToRefreshEnabled"
Value="True"/>
</Style>
how to do like below picture?
thanks #Jason for advice to add backgroundcolor to my labels
We can create two Labels to display Name and Price.
<Grid xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:models="clr-namespace:Notes.Models;assembly=Notes"
x:DataType="models:Goods"
x:Class="Notes.Cells.ProductCard">
<Frame Style="{StaticResource ProductCard}" BackgroundColor="Coral">
<StackLayout Orientation="Horizontal">
<Label
BackgroundColor="Aqua"
HorizontalTextAlignment="Start"
HorizontalOptions="FillAndExpand">
<Label.FormattedText>
<FormattedString>
<Span Text="{Binding Name}" Style="{StaticResource LabelMedium}" BackgroundColor="Blue"></Span>
</FormattedString>
</Label.FormattedText>
</Label>
<Label HorizontalOptions="End">
<Label.FormattedText>
<FormattedString>
<Span Text="Price: " BackgroundColor="Green"/>
<Span Text="{Binding Price}" FontAttributes="Bold" BackgroundColor="Yellow"/>
</FormattedString>
</Label.FormattedText>
</Label>
</StackLayout>
</Frame>
Screen
On the picture above you can see where the ImageButton sometimes activates. When I spam clicking in the blue area the counter sometimes increases. I think there might be another Layer on top of the ImageButton but I dont know how to fix it. Below there is the XAML code. Hopefully somebody can help. Thanks!
<StackLayout>
<Label Text="Discover" TextColor="Black" FontSize="24" FontAttributes="Bold" Margin="15" />
<CarouselView ItemsSource="{Binding plants}" HeightRequest="300" PeekAreaInsets="100">
<CarouselView.ItemTemplate>
<DataTemplate>
<StackLayout>
<Frame HeightRequest="280" WidthRequest="180" BackgroundColor="Wheat" HasShadow="True" Margin="10" Padding="0" HorizontalOptions="CenterAndExpand" CornerRadius="10" >
<Grid>
<StackLayout>
<ImageButton Source="{Binding imgsource}" VerticalOptions="FillAndExpand"
Aspect="AspectFill" Opacity="0.8" Clicked="ImageButton_Clicked"/>
</StackLayout>
<StackLayout Margin="0,10" >
<Image Source="https://icons-for-free.com/iconfiles/png/512/bookmark-131964752402712733.png" HeightRequest="35"
Aspect="AspectFit" HorizontalOptions="EndAndExpand" Margin="5,-15"/>
<Label Text="{Binding name_norm}" TextColor="Black" FontSize="16" FontAttributes="Bold"
Margin="15,-10,0,0" VerticalOptions="EndAndExpand" />
<StackLayout Orientation="Horizontal" Margin="15,-8,0,0" >
<Image Source="https://www.freeiconspng.com/thumbs/info-icon/info-icon-24.png" HeightRequest="15"
Aspect="AspectFit"/>
<Label Text="{Binding name_lat}" TextColor="Black" FontSize="16" FontAttributes="Italic" VerticalOptions="EndAndExpand" Margin="-5,0" />
</StackLayout>
</StackLayout>
</Grid>
</Frame>
</StackLayout>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
<Label x:Name="label" Text="0 ImageButton clicks"
FontSize="Large"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand" />
</StackLayout>
Here the C# Code:
namespace PlantBase
{
public partial class MainPage : ContentPage
{
int clickTotal;
public MainPage()
{
InitializeComponent();
}
private void ImageButton_Clicked(object sender, EventArgs e)
{
clickTotal += 1;
label.Text = $"{clickTotal} ImageButton click{(clickTotal == 1 ? "" : "s")}";
}
}
}
Check VisualElement.InputTransparent Property.
false if the element and its children should receive input; true if neither the element nor its children should receive input and should, instead, pass inputs to the elements that are visually behind the current visual element. Default is false.
What you need is to set InputTransparent to true on the text stackLayout .
<StackLayout InputTransparent="True" Margin="0,10" VerticalOptions="EndAndExpand" BackgroundColor="SaddleBrown">
<Label Text="{Binding name_norm}" TextColor="White" FontSize="16" FontAttributes="Bold" Margin="15,-10,0,0" VerticalOptions="EndAndExpand" />
<StackLayout Orientation="Horizontal" Margin="15,-8,0,0" BackgroundColor="Aqua">
<Image Source="https://www.freeiconspng.com/thumbs/info-icon/info-icon-24.png" HeightRequest="15" Aspect="AspectFit" />
<Label Text="{Binding name_lat}" TextColor="White" FontSize="16" FontAttributes="Italic" VerticalOptions="EndAndExpand" Margin="-5,0" />
</StackLayout>
</StackLayout>
Okay I found the Problem. It was that before I put the red Flag on the Top and the text at the bottom in one Stacklayout which expanded from top to bottom. Now that i put them in seperate StackLayouts it works and the ImageButton is free.
Pictures before/after.
old StackLayout
new Stacklayout
The new XAML is:
<CarouselView ItemsSource="{Binding plants}" HeightRequest="300" PeekAreaInsets="100">
<CarouselView.ItemTemplate>
<DataTemplate>
<StackLayout>
<Frame HeightRequest="280" WidthRequest="180" BackgroundColor="Wheat" HasShadow="True" Margin="10" Padding="0" HorizontalOptions="CenterAndExpand" CornerRadius="10" >
<Grid>
<StackLayout>
<ImageButton Source="{Binding imgsource}" VerticalOptions="FillAndExpand"
Aspect="AspectFill" Opacity="0.9" Clicked="ImageButton_Clicked" />
</StackLayout>
<StackLayout VerticalOptions="StartAndExpand" HorizontalOptions="EndAndExpand" BackgroundColor="Aqua">
<ImageButton Source="https://icons-for-free.com/iconfiles/png/512/bookmark-131964752402712733.png" HeightRequest="35"
Aspect="AspectFit" HorizontalOptions="EndAndExpand" Margin="5,0" BackgroundColor="Transparent" Clicked="ImageButton_Clicked_1" />
</StackLayout>
<StackLayout Margin="0,10" VerticalOptions="EndAndExpand" BackgroundColor="SaddleBrown">
<Label Text="{Binding name_norm}" TextColor="White" FontSize="16" FontAttributes="Bold"
Margin="15,-10,0,0" VerticalOptions="EndAndExpand" />
<StackLayout Orientation="Horizontal" Margin="15,-8,0,0" BackgroundColor="Aqua" >
<Image Source="https://www.freeiconspng.com/thumbs/info-icon/info-icon-24.png" HeightRequest="15"
Aspect="AspectFit" />
<Label Text="{Binding name_lat}" TextColor="White" FontSize="16" FontAttributes="Italic" VerticalOptions="EndAndExpand" Margin="-5,0" />
</StackLayout>
</StackLayout>
</Grid>
</Frame>
</StackLayout>
</DataTemplate>
</CarouselView.ItemTemplate>
New Question now. Since at the bottom there is the Text StackLayout, where the Text is I cant press the ImageButton. How can I put the ImageButton as top "layer" so I can also press it while pressing on the text.
I am trying to manipulate a stacklayout but I cannot getting its name on controller to change it visible or not. How can I do that, is it works on Xamarin ?
Trying
<ContentPage.Content>
<StackLayout HorizontalOptions="FillAndExpand" Padding="2">
<StackLayout HorizontalOptions="FillAndExpand">
<Label Text="Compre agora seu número da sorte"
FontSize="Small"
TextColor="Gray"
FontAttributes="Bold"
HorizontalOptions="CenterAndExpand"
/>
</StackLayout>
<StackLayout HorizontalOptions="FillAndExpand">
<Label Text="Concurso" FontAttributes="Bold"></Label>
<Label x:Name="idConcurso"></Label>
<Label Text="Prêmio" FontAttributes="Bold"></Label>
<Label x:Name="premioNome"></Label>
</StackLayout>
<StackLayout HorizontalOptions="FillAndExpand">
<ListView x:Name="GridNumerosDaSorte"
SeparatorVisibility="Default"
HasUnevenRows="true"
ItemAppearing="OnItemAppearing"
>
<ListView.Header>
<StackLayout Orientation="Horizontal" BackgroundColor="#335D3B">
<Label Text="Nº da Sorte" TextColor="#FFF" HorizontalOptions="StartAndExpand" ></Label>
<Label Text="Valor(R$)" TextColor="#FFF" HorizontalOptions="CenterAndExpand" ></Label>
<Label Text="Controle" TextColor="#335D3B" HorizontalOptions="EndAndExpand" ></Label>
</StackLayout>
</ListView.Header>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal" Margin="0,10,0,0">
<Label Text="{Binding numero}" HorizontalOptions="StartAndExpand"></Label>
<Label Text="{Binding valor, StringFormat='{}{0:N}'}" HorizontalOptions="EndAndExpand" ></Label>
<Button Text="Comprar" Clicked="OnComprarClick" CommandParameter="{Binding .}" HorizontalOptions="EndAndExpand" BackgroundColor="Orange"></Button>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
<StackLayout x:Name="FooterPanel" HorizontalOptions="FillAndExpand" IsVisible="False">
<Label Text="text 1" HorizontalOptions="StartAndExpand"></Label>
<Label Text="text 2" HorizontalOptions="CenterAndExpand"></Label>
<Label Text="text 3" HorizontalOptions="EndAndExpand"></Label>
</StackLayout>
</StackLayout>
</ContentPage.Content>
Controller
//x:Name does not appear on controller, it does not works
FooterPanel.isVisible = true;
I'm working on a Xamarin Forms project using Visual studio 2017 , I want to add a border to the web view . with black color . how to do that view xaml is below .
<StackLayout Orientation="Vertical" BackgroundColor="White" HorizontalOptions="FillAndExpand">
<StackLayout Orientation="Horizontal" HeightRequest="60" HorizontalOptions="FillAndExpand" BackgroundColor="DarkBlue" Padding="5">
<Label x:Name="lblUserNewOnBoarding" WidthRequest="340" Text="New User Onboarding" FontAttributes="Bold" FontFamily="Roboto" FontSize="Large" TextColor="White"
HorizontalOptions="StartAndExpand" VerticalOptions="CenterAndExpand"></Label>
<Button x:Name="bntCancel" Text="Cancel" HeightRequest="40" BackgroundColor="#4184f3"
TextColor="White" HorizontalOptions="EndAndExpand" VerticalOptions="CenterAndExpand" Clicked="HandleCancle_Clicked" FontFamily="Roboto" FontSize="Small" FontAttributes="Bold">
<Button.Image>
<FileImageSource File="baseline_cancel_white_18dp.png" ></FileImageSource>
</Button.Image>
</Button>
</StackLayout>
<StackLayout Orientation="Vertical" HorizontalOptions="CenterAndExpand" >
<Label Text="Please agree to the following terms and conditions…" FontFamily="Roboto-Medium" FontSize="30"
HorizontalOptions="CenterAndExpand" WidthRequest="927" HeightRequest="168" Margin="5"
TextColor="Black"></Label>
<WebView x:Name="wvAgree" HeightRequest="300" WidthRequest="400" Margin="50" BackgroundColor="White" ></WebView>
<Button x:Name="btnAgree" Text="Agree" WidthRequest="190" HeightRequest="50" AnchorX="417" AnchorY="604"
BackgroundColor="#4184f3" TextColor="White" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" Clicked="HandleAgree_Clicked" FontFamily="Roboto" FontSize="Small" FontAttributes="Bold">
<Button.Image >
<FileImageSource File="Agree.png"></FileImageSource>
</Button.Image>
</Button>
<Button x:Name="btnDisAgree" Text="Disagree" WidthRequest="190" HeightRequest="50" AnchorX="417" AnchorY="673" BackgroundColor="#4184f3"
TextColor="White" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" Clicked="HandleDisAgree_Clicked" FontFamily="Roboto" FontSize="Small" FontAttributes="Bold">
<Button.Image>
<FileImageSource File="baseline_delete_48.png" ></FileImageSource>
</Button.Image>
</Button>
</StackLayout>
</StackLayout>
Wrap your WebView around Frame. So:
<Frame OutlineColor="Black">
<WebView x:Name="wvAgree" HeightRequest="300" WidthRequest="400" Margin="50" BackgroundColor="White"/>
</Frame>
Also you dont have to write a Additional closing Tag if you dont put anything between it. Pay attention how I closed that WebView tag.
Here is the code that I am using with Xamarin Forms:
<Grid Grid.Column="0" ColumnSpacing="0" Margin="0,0,10,0">
<Label Grid.Column="0" x:Name="faveIconLabel" Style="{StaticResource mediumIcon}" Margin="0,2,0,0" HorizontalOptions="Fill" FontFamily="FontAwesome" VerticalOptions="Center" VerticalTextAlignment="Center" />
<Label Grid.Column="1" x:Name="hiddenIconLabel" Style="{StaticResource mediumIcon}" Margin="0,2,0,0" HorizontalOptions="Fill" FontFamily="FontAwesome" VerticalOptions="Center" VerticalTextAlignment="Center" />
</Grid>
Can someone help and let me know how I can surround these two labels with a border to make them as much as possible look like buttons.
Frame can be used for this very purpose:
<Grid Grid.Column="0" ColumnSpacing="0" Margin="0,0,10,0">
<Frame Grid.Column="0" CornerRadius="5" OutlineColor="Black">
<Label x:Name="faveIconLabel" Style="{StaticResource mediumIcon}" Margin="0,2,0,0" HorizontalOptions="Fill" FontFamily="FontAwesome" VerticalOptions="Center" VerticalTextAlignment="Center" />
</Frame>
<Frame Grid.Column="1" CornerRadius="5" OutlineColor="Black">
<Label x:Name="hiddenIconLabel" Style="{StaticResource mediumIcon}" Margin="0,2,0,0" HorizontalOptions="Fill" FontFamily="FontAwesome" VerticalOptions="Center" VerticalTextAlignment="Center" />
</Frame>
</Grid>