【问题标题】:Setting child height or width to parent control same as "match_parent" in android将子高度或宽度设置为父控件与android中的“match_parent”相同
【发布时间】:2023-10-19 05:26:01
【问题描述】:

我有一个包含网格的页面,并且在该网格中有一张地图。但我无法将地图的大小设置为与网格大小相同。虽然我可以在代码中将其设置为

MyMap.Height = LayoutRoot.ActualHeight;
MyMap.Width = LayoutRoot.ActualWidth;

但是如何在 xaml 中设置它。

<phone:PhoneApplicationPage
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:maps="clr-namespace:Microsoft.Phone.Maps.Controls;assembly=Microsoft.Phone.Maps"
    x:Class="MapSample.MainPage"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True">

    <Grid x:Name="LayoutRoot" Background="Red">
        <maps:Map x:Name="MyMap" HorizontalAlignment="Left" VerticalAlignment="Top" Center="47.6097, -122.3331" ZoomLevel="10"/>
    </Grid>

</phone:PhoneApplicationPage>

【问题讨论】:

    标签: c# xaml windows-8 windows-phone-8


    【解决方案1】:

    你应该将地图控件的HorizontalAlignmentVerticalAlignment设置为Stretch

    <maps:Map x:Name="MyMap"
              HorizontalAlignment="Stretch"
              VerticalAlignment="Stretch"
              Center="47.6097, -122.3331"
              ZoomLevel="10" />
    

    【讨论】:

      最近更新 更多