2017-12-14 6 views
1

このコンテンツページを初期化しようとすると、コードがクラッシュします。静的リソース以外はすべて正常に動作しますが、残りのコメントを外してみました。静的リソースにのみ問題があります。コメントアウトされたコードのみが機能しません。Xaml FontSizeを使用したStaticResourceバインディングスタイルのクラッシュ

私はあなたがNamedSize列挙経由のFontSizeを設定するためにStyleを使用することができますOnPlatform要件に

<?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="ASFT.IssueManager.LoginPage" Padding="10"> 
     <ContentPage.Resources> 
      <ResourceDictionary> 
      <x:String x:Key="Labelfont">Medium</x:String> 
      <x:String x:Key="Titlefont">Large</x:String> 
     </ResourceDictionary> 
     </ContentPage.Resources> 
     <StackLayout Orientation="Vertical" VerticalOptions="Center" HorizontalOptions="FillAndExpand" Spacing="10" > 
     <StackLayout Orientation="Vertical" VerticalOptions="Start" HorizontalOptions="Center" Spacing="10" WidthRequest="350"> 
      <Label Text="Login" VerticalOptions="Center" HorizontalOptions="Start" FontSize="{StaticResource Titlefont}"/> 
      <BoxView HeightRequest="5" Color="Gray"/> 
      <!--<Label Text="Host" VerticalOptions="Center" HorizontalOptions="Start" FontSize="{StaticResource Labelfont}"/> 
      <Entry Placeholder="Host/URL" Text="{Binding Host}" /> 
      <Label Text="UserName" VerticalOptions="Center" HorizontalOptions="Start" FontSize="{StaticResource Labelfont}"/> 
      <Entry Placeholder="User name/Account" Text="{Binding Username}" /> 
      <Label Text="Password" VerticalOptions="Center" HorizontalOptions="Start" FontSize="{StaticResource Labelfont}"/> 
      <Entry Placeholder="Password" IsPassword="true" Text="{Binding Password}" /> 
      <BoxView HeightRequest="5" Color="Gray"/>--> 
      <Button x:Name="btnLogin" Text="Login" HorizontalOptions="FillAndExpand" Clicked="OnButtonLogin" WidthRequest="100"/> 
     </StackLayout> 
     </StackLayout> 
    </ContentPage> 
+2

可能な重複 - ラベルFontSize OnPlatform - XAMLエラー](https://stackoverflow.co m/questions/46274052/xamarin-forms-label-fontsize-onplatform-xaml-error) – EvZ

+0

私はonPlatformを使用していません –

答えて

1

を使用しないでください。スタイルを参照する

<ResourceDictionary> 
    <Style x:Key="Labelfont" TargetType="Label"> 
     <Setter Property="FontSize" Value="Small" /> 
    </Style> 
    <Style x:Key="Titlefont" TargetType="Label"> 
     <Setter Property="FontSize" Value="Large" /> 
    </Style> 
</ResourceDictionary> 

変更は、あなたのコントロール::

変更のResourceDictionaryを使用するスタイル

<StackLayout Orientation="Vertical" VerticalOptions="Center" HorizontalOptions="FillAndExpand" Spacing="10" > 
    <StackLayout Orientation="Vertical" VerticalOptions="Start" HorizontalOptions="Center" Spacing="10" WidthRequest="350"> 
      <Label Text="Login" VerticalOptions="Center" HorizontalOptions="Start" Style="{StaticResource Titlefont}"/> 
      <BoxView HeightRequest="5" Color="Gray"/> 
      <Label Text="Host" VerticalOptions="Center" HorizontalOptions="Start" Style="{StaticResource Labelfont}"/> 
      <Entry Placeholder="Host/URL" /> 
      <Label Text="UserName" VerticalOptions="Center" HorizontalOptions="Start" Style="{StaticResource Labelfont}"/> 
      <Entry Placeholder="User name/Account" /> 
      <Label Text="Password" VerticalOptions="Center" HorizontalOptions="Start" Style="{StaticResource Labelfont}"/> 
      <Entry Placeholder="Password" IsPassword="true" /> 
      <BoxView HeightRequest="5" Color="Gray"/> 
      <Button x:Name="btnLogin" Text="Login" HorizontalOptions="FillAndExpand" WidthRequest="100"/> 
    </StackLayout> 
</StackLayout> 

出力:[Xamarin.Formsの

enter image description here

関連する問題