0

我有一个非常简单和基本的问题,但不知道如何克服它。我想支持 snappedview 并且我已经支持它,但不完全支持。

我无法显示具有名称的控件。例如,我有一个 bing 地图控件(它不适用于绑定...)。所以我需要给它一个名字和每一个动作来改变它背后的代码。下面是控制示例:

<map:Map x:Name="map"
         Credentials="{StaticResource BingCredentials}"
         Tapped="Map_Tapped"
         Loaded="Map_Loaded">
         <map:Map.Children>
             <map:MapItemsControl ItemTemplate="{StaticResource PushpinLocalTemplate}" ItemsSource="{Binding PushpinModel}" />
         </map:Map.Children>
</map:Map>

所以,我不能在多个视图中显示它(FullView 或 SnappedView ...)。问题是,如果我将它写在 datatemplate 中,那么后面的代码就无法访问该名称,因此我的所有代码都无法编译。

我能做些什么?也许是用户控件?如果是,如何?

非常感谢!

4

1 回答 1

1

我希望这会有所帮助,此示例将地图隐藏在快照视图中。您可以更改Visibility您想要的任何属性和Collapsed所需的值。请注意地图名为CoolMap,如果您使用不同的名称,也请更改它。

<common:LayoutAwarePage
    x:Class="BingMapsApp.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:BingMapsApp"
    xmlns:map="using:Bing.Maps"
    xmlns:common="using:BingMapsApp.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <map:Map x:Name="CoolMap" Credentials="{StaticResource BingCredentials}">
            <map:Map.Children>
                <map:MapItemsControl ItemTemplate="{StaticResource PushpinLocalTemplate}" ItemsSource="{Binding PushpinModel}">
                    <x:String>blah blah blah</x:String>
                </map:MapItemsControl>
            </map:Map.Children>
        </map:Map>

        <VisualStateManager.VisualStateGroups>
            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>
                <VisualState x:Name="FullScreenPortrait" />

                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CoolMap" Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed" />
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>

使用 修改任何属性ObjectAnimationUsingKeyFrames

于 2013-09-28T19:40:26.063 回答