Bug 42767 - Custom font label not working in ListView
Summary: Custom font label not working in ListView
Status: RESOLVED INVALID
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.1
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-07-22 23:04 UTC by chkrishna2001
Modified: 2016-07-27 00:39 UTC (History)
2 users (show)

Tags: xamarin forms, custom font, custom control
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED INVALID

Description chkrishna2001 2016-07-22 23:04:38 UTC
I have a custom label to show custom(telugu) font which works well in normal view, but when I keep this Label in a listview it's empty. Anybody faced this problem ? The label has a renderer in android to set font that's it, somehow it don't work in listview
Label class
 
public class TeluguLabel:Label
{
    public TeluguLabel()
    {
    }

}

Android renderer

using Android.Graphics;
using TestTeluguLabel;
using TestTeluguLabel.Droid;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;

[assembly: ExportRenderer(typeof(TeluguLabel), typeof(TeluguLabelRenderer))]
namespace TestTeluguLabel.Droid
{
    public class TeluguLabelRenderer:LabelRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
        {
            base.OnElementChanged(e);
            var label = Control;
            label.SetMaxLines(4000);
            Typeface font = Typeface.CreateFromAsset(Forms.Context.Assets, "fonts/" + e.NewElement.FontFamily);
            label.Typeface = font;
        }
    }
}
Label XAML
<Grid >
    <Grid.RowDefinitions>
      <RowDefinition Height=".3*" />
      <RowDefinition Height=".7*" />
    </Grid.RowDefinitions>
  
  <StackLayout Grid.Row="0" Padding="10" Spacing="20">
    <Label Text="This is a normal label outside list view below is custom lable with telugu font applied" />
    <Frame BackgroundColor="Red"  >
    <local:TeluguLabel Text="testing telugu label outside list view  శ్రీ హయగ్రీవాయనమః" TextColor="White"   FontSize="Large"  >
      <local:TeluguLabel.FontFamily>
        <OnPlatform x:TypeArguments="x:String">
          <OnPlatform.iOS>gautami</OnPlatform.iOS>
          <OnPlatform.Android>gautami.ttf</OnPlatform.Android>
          <OnPlatform.WinPhone>/Assets/fonts/gautami.ttf#Gautami</OnPlatform.WinPhone>
        </OnPlatform>
      </local:TeluguLabel.FontFamily>
    </local:TeluguLabel>
    </Frame>
  </StackLayout>
 
  <ListView x:Name="lvLabels" Grid.Row="1" >
    <ListView.ItemTemplate>
      <DataTemplate>
        <ViewCell>
          <ViewCell.View>
            <StackLayout Padding="10" Spacing="20">
              <Label Text="{Binding englishtext}" />
              <Frame BackgroundColor="Red">
              <local:TeluguLabel Text="{Binding telugtext}" TextColor="White"  FontSize="Large"  >
                <local:TeluguLabel.FontFamily>
                  <OnPlatform x:TypeArguments="x:String">
                    <OnPlatform.iOS>gautami</OnPlatform.iOS>
                    <OnPlatform.Android>gautami.ttf</OnPlatform.Android>
                    <OnPlatform.WinPhone>/Assets/fonts/gautami.ttf#Gautami</OnPlatform.WinPhone>
                  </OnPlatform>
                </local:TeluguLabel.FontFamily>
              </local:TeluguLabel>
              </Frame>
            </StackLayout>
          </ViewCell.View>
        </ViewCell>
      </DataTemplate>
    </ListView.ItemTemplate>
  </ListView>
  </Grid>
</ContentPage>
Comment 1 chkrishna2001 2016-07-27 00:39:30 UTC
My mistake tested wrongly, it's working fine