c# - Windows Phone 8 map 不显示在用户控件中

标签 c# xaml windows-phone-8 user-controls maps

我想在我的应用程序中实现“附加位置”功能。 我决定创建一个用户控件并将我的 map 放入其中,然后在单击某个按钮后,我会在全屏弹出窗口/自定义消息框中显示此控件。

问题是除了 map 没有显示外,一切正常;我可以检索我的位置、放置图钉、缩放功能(尽管我什么也没看到!)。

更奇怪的是,复制并粘贴到手机应用程序页面的相同代码工作正常并且 map 出现了。我不明白,这是我不知道的限制吗?

这是我的代码:

    <UserControl
       .....
        xmlns:maps="clr-namespace:Microsoft.Phone.Controls.Maps;assembly=Microsoft.Phone.Controls.Maps"
        mc:Ignorable="d"
     ....
    >
<Grid x:Name="LayoutRoot" Background="Black">

        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <maps:Map Mode="AerialWithLabels"  
                    Grid.Row="0" 
                    Height="300" 
                    HorizontalAlignment="Left" 
                    Name="map1" VerticalAlignment="Top" 
                    Width="460" Margin="-12,0,0,0">
            </maps:Map>
            <Button Content="share location" 
                    Name="btn_SendLocation" 
                    IsEnabled="False" 
                    Grid.Row="1" 
                    Click="Button_Click_1"/>
            <ListBox Grid.Row="2" 
                     Name="lst_NearBy" 
                     DataContext="{Binding Location}" 
                     Tap="lst_NearBy_Tap">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Margin="0,5">
                            <TextBlock Text="{Binding mName}" Style="{StaticResource PhoneTextLargeStyle}"/>
                            <TextBlock Text="{Binding mVicinity}" Margin="10,0,0,0" Foreground="Gray"/>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Grid>
    </Grid>

最佳答案

您是否尝试以编程方式添加 map ?

private Constructor()
{
    Map my_map = new Map();
    my_map.Name= "map1";
    my_map.mode = "AerialWithLabels";
    my_map.Height = 300;
    my_map.Margin = new Thickness(-12,0,0,0);
    my_map.VerticalAlignment = System.Windows.VerticalAlignment.Top;
    my_map.HorizontalAlignment= System.Windows.HorizontalAlignment.Left;
    ContentPanel.Children.Add(my_map);
}

关于c# - Windows Phone 8 map 不显示在用户控件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21450140/

相关文章:

wpf - 在 MyUserControl.xaml 中以声明方式设置 MyUserControl 的属性

windows-phone-8 - windows phone 8系统编译lua失败

xaml - WinRT XAML 工具包预加载页面

c# - 水平堆栈面板上 ListItem 之间的间距

c# - 将 bytes[] 转换为文字字符串

c# - NAudio 未读取包含 wav 数据的 MemoryStream

c# - 写入项目文件夹中的文件 - 不允许操作

Windows 8 和 Windows 电话 8

C#/WP7 : Working with a JSON object that includes an array of JSON objects

c# - Parallel.ForEach 未按 C# 中 ConcurrentBag 中的预期添加项目