2016-11-23 15 views
0

MasterDetailページのマスターページ内にラベルラップを作成しようとしています。ラベルをラップするのはデフォルトの動作だと思っていましたが、カスタムレンダラーを作った場合でもそうです。私はカスタムレンダラが動作していることを確認しています(デバッグとラベルのバックグラウンドの追加によって)、私は紛失しているものがあると思います。誰でも私のxamlを見て、なぜこのラベルが折り返していないのか考えてもらえますか?私のXamarin.Formsラベルでテキストが折り返されないのはなぜですか?

<?xml version="1.0" encoding="utf-8" ?> 
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
      x:Class="MyApp.Pages.NavigationDrawer.NavigationMenuMasterPage" 
      xmlns:statics="clr-namespace:MyApp.Statics;assembly=MyApp" 
      xmlns:multi="clr-namespace:MyApp.Pages.NavigationDrawer;assembly=MyApp" 
      Title="Navigation drawer" 
      Icon="hamburger.png" 
      BackgroundColor="White"> 
    <ContentPage.Content> 
     <StackLayout VerticalOptions="FillAndExpand" HorizontalOptions="Center" Margin="0, 25, 0, 0"> 
      <StackLayout Orientation="Horizontal" HorizontalOptions="Center"> 
       <Image x:Name="connectionStatusImage" /> 
       <Label x:Name="connectionStatusText" Margin="16, 0, 16, 0" YAlign="Center" FontSize="Medium"/> 
      </StackLayout> 
      <Label x:Name="changeConnectionStatusButton" TextColor="{x:Static statics:Palette.Orange}" XAlign="Center" FontAttributes="Bold" > 
       <Label.GestureRecognizers> 
        <TapGestureRecognizer Tapped="ChangeConnectionStatusClicked" NumberOfTapsRequired="1" /> 
       </Label.GestureRecognizers> 
      </Label> 
      <StackLayout x:Name="SyncStatusStack" Orientation="Horizontal" Margin="0, 16, 16, 0" VerticalOptions="Center" > 
       <multi:MultiLineLabel x:Name="syncStatusText" MinimumWidthRequest="0" Margin="16, 0, 0, 0" Text="I want to write a really long string to see if it wraps" /> 
       <Label x:Name="syncButton" MinimumWidthRequest="40" Text="SYNC" FontAttributes="Bold" YAlign="Center" HorizontalOptions="End" > 
        <Label.GestureRecognizers> 
         <TapGestureRecognizer x:Name="SyncGestureRecognizer" NumberOfTapsRequired="1" /> 
        </Label.GestureRecognizers> 
       </Label> 
      </StackLayout> 
      <StackLayout x:Name="SyncStack" Orientation="Vertical" HorizontalOptions="Center" Margin="0, 16, 0, 0"> 
       <ActivityIndicator x:Name="syncingIndicator" Margin="16, 0, 32, 0"/> 
       <Label x:Name="syncingText" /> 
      </StackLayout> 
      <ListView x:Name="menuListView" VerticalOptions="FillAndExpand" SeparatorVisibility="None" Margin="0, 16, 0, 0"> 
       <ListView.ItemTemplate> 
        <DataTemplate> 
         <TextCell Text="{Binding Title}" TextColor="{x:Static statics:Palette.PrimaryText}" /> 
        </DataTemplate> 
       </ListView.ItemTemplate> 
      </ListView> 
     </StackLayout> 
    </ContentPage.Content> 
</ContentPage> 

そして、私の(ほとんどの場合不要)カスタムラベルレンダラ:

using MyApp.iOS.Renderers; 
using MyApp.Pages.NavigationDrawer; 
using Xamarin.Forms; 
using Xamarin.Forms.Platform.iOS; 

[assembly: ExportRenderer(typeof(MultiLineLabel), typeof(MultiLineLabeliOSRenderer))] 
namespace MyApp.iOS.Renderers 
{ 
    public class MultiLineLabeliOSRenderer : LabelRenderer 
    { 
     protected override void OnElementChanged(ElementChangedEventArgs<Label> e) 
     { 
      base.OnElementChanged(e); 

      if (Control == null) return; 

      Control.LineBreakMode = UIKit.UILineBreakMode.WordWrap; 
      Control.Lines = 0;    
     } 
    } 
} 

screenshot of the issue

答えて

0

なぜうーんわからないが、あなたは0に正しい設定線であるとワードラップを使用して行う必要がありますトリック(Multiple lines of text in UILabel

最近私はカスタムレンダラ(http://depblog.weblogs.us/2016/06/27/xamarin-forms-multi-line-label-custom-renderer-gotcha/)でこれを実装し、数字をind私が持っていると思っている線の正確な量を表示してください。 これはLinesプロパティに設定され、ラッピングが機能します。

+1

私は別の場所にラベルを置いて、別の場所に(たとえ基本的なListViewを持つ新しいページ上でも)横のStackLayoutsの中にラベルを置いています。水平StackLayoutのラベルが折り返されないようです同じページにListViewがある場合、iOS。 ListViewがない場合、すべてが期待通りに機能します。そして、それはすべてAndroid上で正常に動作します。だから私はこれがバグでなければならないと仮定しています。私はグリッドと同じ動作をしました。だから、ちょうど私のレイアウトを少し変更し、StackLayoutを垂直にしました。正確には私が望んでいたものではありませんが、それは動作します:) –

+1

BugZillaにリポジトリを投稿すると、それが追跡されます! – Depechie

+0

@JasonTomsは正しい - 私はちょうどこれを打つ...何時間の無駄。レイアウトを維持したい場合は、LineBreakModeを使って調整することができます。 – thinice

関連する問題