listboxitem的Windows手机侧面菜单

时间:2014-08-28 14:03:51

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

我想为特定的listboxitem或longlistselector项创建一个侧边菜单 比如图片enter image description here

当您按住listboxitem时,蓝色面板出现,无论如何都有吗?

我在项目上管理了Hold事件,但没有管理侧边菜单!

2 个答案:

答案 0 :(得分:1)

您可以在Item Template中添加此菜单,并将其Visibility设置为Collapsed。然后将代码添加到将显示它的Hold事件中。请查看Storyboard课程,了解可能的动画。

答案 1 :(得分:1)

有几种可能的方法可以做到这一点,但基本思路是将菜单添加到隐藏或折叠状态,然后在Hold事件上触发动画。这是一个简单的例子(使用交互DLL System.Windows.Interactivity和Microsoft.Expression.Interactions.Core):

<Grid xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
      xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions">
    <Grid.Resources>
        <Storyboard x:Name="ShowMenu">
            <DoubleAnimation Storyboard.TargetName="translate" Storyboard.TargetProperty="X" 
                             To="0" Duration="0:0:0.3" />
        </Storyboard>
        <Storyboard x:Name="HideMenu">
            <DoubleAnimation Storyboard.TargetName="translate" Storyboard.TargetProperty="X" 
                             To="-300" Duration="0:0:0.3" />
        </Storyboard>
    </Grid.Resources>

    <Grid Width="300" Background="LightBlue">
        <Grid.RenderTransform>
            <TranslateTransform x:Name="translate" X="-300" />
        </Grid.RenderTransform>

        <!-- Menu popup content here -->
        <TextBlock Text="Menu">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="Hold">
                    <ei:ControlStoryboardAction Storyboard="{StaticResource HideMenu}" ControlStoryboardOption="Play" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </TextBlock>
    </Grid>

    <Grid>
        <!-- Item content here -->
        <TextBlock Text="Item">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="Hold">
                    <ei:ControlStoryboardAction Storyboard="{StaticResource ShowMenu}" ControlStoryboardOption="Play" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </TextBlock
    </Grid>
</Grid>