2016-09-17 20 views
0

ボタンのためにStyleを作成しましたが、長いテキストを使用すると、は切り捨てられますボタンを展開してXamarin.Formsのテキストを表示する方法

これはスタイルです:

<Style x:Key="DefaultButton" TargetType="Button"> 
     <!--<Setter Property="WidthRequest"> 
      <Setter.Value> 
       <OnIdiom x:TypeArguments="x:Double" 
         Phone="150" 
         Tablet="200" /> 
      </Setter.Value> 
     </Setter> 
     <Setter Property="HeightRequest"> 
      <Setter.Value> 
       <OnIdiom x:TypeArguments="x:Double" 
         Phone="70" 
         Tablet="100" /> 
      </Setter.Value> 
     </Setter>--> 
     <Setter Property="BackgroundColor" Value="{StaticResource BaseColor}" /> 
     <Setter Property="TextColor" Value="White" /> 
     <Setter Property="HorizontalOptions" Value="CenterAndExpand" /> 
     <Setter Property="VerticalOptions" Value="FillAndExpand" /> 
     <Setter Property="Margin" Value="5" /> 
     <Setter Property="FontSize"> 
      <Setter.Value> 
       <OnIdiom x:TypeArguments="x:Double" 
         Phone="20" 
         Tablet="25" /> 
      </Setter.Value> 
     </Setter> 
    </Style> 

ボタン:

<Button Grid.Row="1" 
      Grid.Column="1" 
      Style="{DynamicResource DefaultButton}" 
      Text="Basic button with long text" /> 

これは、長いテキストとそのボタンがどのように見えるかです:

enter image description here

私が設定することができます非常に大きいHeightRequestボタンのためにそれはver y悪い習慣。

どうすればよいですか?

+0

をあなたは常に高さ設定要求を省略すると、ボタンの大きさ自体を聞かせてことができます。それを明示的に設定しなければならない理由はありますか? –

+0

@WilliamCorncobDeckerあなたは私を誤解しているかもしれません。 HeigthRequestを明示的に設定したくない(コメントアウトされています)、私はそれを自動サイズにしたいと思います。どうしたらいいですか? – Nestor

答えて

0

私は、多くの場合、ボタンを補うためにBoxViewLabelGridを使用して、GridGestureRecognizerを配置します。必要に応じて、このすべてをカスタムコントロールに追加して、簡単に再利用できます。

それはいくつかの固定が必要な場合がありますので、私はメモリから下記のGestureRecognizerをした:

<Grid x:Name="BasicButtonGrid" 
     VerticalOptions="End"> 
    <Grid.ColumnDefinitions> 
    <ColumnDefinition Width="*"/> 
    </Grid.ColumnDefinitions> 
    <Grid.RowDefinitions> 
    <RowDefinition Height="*"/> 
    </Grid.RowDefinitions> 

    <Grid.MinimumHeightRequest> 
    <OnIdiom x:TypeArguments="x:Double" 
      Phone="40" 
      Tablet="70"/> 
    </Grid.MinimumHeightRequest> 

    <Grid.GestureRecognizers> 
    <TapGestureRecognizer Tapped="OnBasicButtonTapped"/> 
    </Grid.GestureRecognizers> 

    <BoxView BackgroundColor="Blue" 
      VerticalOptions="EndAndExpand" 
      InputTransparent="True" 
      Grid.Row="0" 
      Grid.Column="0"/> 

    <Label Text="Basic Button with long text" 
     TextColor="White" 
     FontSize="Medium" 
     Grid.Row="0" 
     Grid.Column="0"/> 
</Grid> 
関連する問題