如何在 C# 中展开网格中的地图

本文关键字:网格 地图 | 更新日期: 2023-09-27 18:17:10

xaml

<Grid x:Name="LayoutRoot">    
<maps:Map x:Name="mapWithMyLocation" HorizontalAlignment="Left" Margin="1,0,0,443" VerticalAlignment="Bottom" Height="233" Width="479" ZoomLevel="10"/>
    <Grid Margin="0,0,0,77" Grid.Row="1" RenderTransformOrigin="0.5,0.5" Height="366" VerticalAlignment="Bottom" Grid.ColumnSpan="2">
        <phone:LongListSelector x:Name="closestBusList" ItemsSource="{Binding KioskList}" SelectionChanged="closestBusList_SelectionChanged_1" Height="366" VerticalAlignment="Top">
            <phone:LongListSelector.ItemTemplate>
                 <DataTemplate>
                     <StackPanel Orientation="Vertical" Opacity="0.5" Background="WhiteSmoke">
                         <TextBlock FontWeight="Bold" Foreground="#0145A6" FontSize="14" x:Name="owner" Text="{Binding owner}"></TextBlock>
                         <TextBlock FontWeight="Bold" Foreground="#038edf" FontSize="12" x:Name="addres" Text="{Binding address}"></TextBlock>
                     </StackPanel>
                 </DataTemplate>
             </phone:LongListSelector.ItemTemplate>
         </phone:LongListSelector>
     </Grid>
</Grid>

.cs

private void expand_btn_Click(object sender, RoutedEventArgs e)
{
    double height = this.mapWithMyLocation.Height;
    double from, to;
    // animate from 150 to 800, or vice versa
    if (height == 233)
    {
        from = 233;
        to = 800;
        closestBusList.Visibility = Visibility.Collapsed;
    }
    else
    {
        from = 800;
        to = 233;
        closestBusList.Visibility = Visibility.Visible;
    }
    Storyboard sb = new System.Windows.Media.Animation.Storyboard();
    DoubleAnimation fillHeightAnimation = new System.Windows.Media.Animation.DoubleAnimation();
    fillHeightAnimation.From = from;
    fillHeightAnimation.To = to;
    fillHeightAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.3));
    Storyboard.SetTarget(fillHeightAnimation, this.mapWithMyLocation);
    Storyboard.SetTargetProperty(fillHeightAnimation, new PropertyPath("Height"));
    sb.Children.Add(fillHeightAnimation);
    sb.Begin();
}

如何在 C# 中展开网格中的地图

添加三行定义并在网格内添加地图后,问题解决了。