2016-12-31 12 views
1

場所の詳細(緯度/経度を含む)を受け取り、マップとその詳細を表示するページを作成しました。 このコードを使用すると、AndroidエミュレータでUIが適切にレンダリングされます。 XAMLでこれを実行しようとすると、XAMLのコードを可能な限り複製することにもかかわらず、正しく表示されません。Xamarin Xaml StackLayout over Map

コードである:これは、としてレンダリング

public class TestDetailPage : ContentPage 
{ 

    public TestDetailPage(TripLogEntry entry) { 

     Title = "Entry Details"; 
     var mainLayout = new Grid 
     { 
      RowDefinitions = { 
       new RowDefinition { Height = new GridLength (4, GridUnitType.Star) }, 
       new RowDefinition { Height = GridLength.Auto }, 
       new RowDefinition { Height = new GridLength (1, GridUnitType.Star) }} 
     }; 

     var map = new Map(); 
     // Center the map around the log entry's location 
     map.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(entry.Latitude, entry.Longitude), Distance.FromMiles(.5))); 
     // Place a pin on the map for the log entry's location 
     map.Pins.Add(new Pin 
     { 
      Type = PinType.Place, 
      Label = entry.Title, 
      Position = new Position(entry.Latitude, entry.Longitude) 
     }); 
     var title = new Label 
     { 
      HorizontalOptions = LayoutOptions.Center 
     }; 
     title.Text = entry.Title; 
     var date = new Label 
     { 
      HorizontalOptions = LayoutOptions.Center 
     }; 
     date.Text = entry.Date.ToString("M"); 
     var rating = new Label 
     { 
      HorizontalOptions = LayoutOptions.Center 
     }; 
     rating.Text = $"{entry.Rating} star rating"; 
     var notes = new Label 
     { 
      HorizontalOptions = LayoutOptions.Center 
     }; 
     notes.Text = entry.Notes; 
     var details = new StackLayout 
     { 
      Padding = 10, 
      Children = { title, date, rating, notes } 
     }; 
     var detailsBg = new BoxView 
     { 
      BackgroundColor = Color.White, 
      Opacity = .8 
     }; 
     mainLayout.Children.Add(map); 
     mainLayout.Children.Add(detailsBg, 0, 1); 
     mainLayout.Children.Add(details, 0, 1); 
     Grid.SetRowSpan(map, 3); 
     Content = mainLayout; 
    } 
} 

:XAMLで Map when using code

それが示されるようにレンダリング下記

<?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="TripLog.Pages.DetailPage" Title="Entry Details" 
     xmlns:map="clr-namespace:Xamarin.Forms.Maps;assembly=Xamarin.Forms.Maps"> 
    <ContentPage.Content> 
    <Grid> 
     <Grid.RowDefinitions> 
     <RowDefinition Height="4*" /> 
     <RowDefinition Height="Auto" /> 
     <RowDefinition Height="1*" /> 
     </Grid.RowDefinitions>  
     <map:Map x:Name="DetailMap" Grid.RowSpan="3" /> 
     <BoxView x:Name="DetailsBG" BackgroundColor="Color.White" Grid.Row="0" Grid.Column="1" /> 
     <StackLayout Padding="10" Grid.Row="0" Grid.Column="1"> 
     <Label x:Name="EntryTitle" /> 
     <Label x:Name="EntryDate" /> 
     <Label x:Name="EntryRating" /> 
     <Label x:Name="EntryNotes" /> 
     </StackLayout>   
    </Grid>  
    </ContentPage.Content> 
</ContentPage> 

Map when using XAML

ご覧のとおり、コードをXAMLにコピーしようとしましたが、無駄です。 XAMLのコードで同じUIレンダリングを手伝ってもらえますか?

ありがとうございました。

答えて

0

Grid.Children.Add(Element, Col, Row)の引数は、直感的ではありません。 XAMLでは、列と行の値を転置しています。働い

<BoxView x:Name="DetailsBG" BackgroundColor="Color.White" Grid.Row="1" Grid.Column="0" /> 
    <StackLayout Padding="10" Grid.Row="1" Grid.Column="0"> 
+0

はそれを切り替えてみてください。そのジェイソンのおかげで多くの。 Grid.Row = "1" Grid.Column = "0"がXAMLに混在していました。 –

関連する問題