Windows Phone 7滑动菜单

时间:2014-07-29 09:22:13

标签: windows-phone-7 slidingmenu

我正在开发Windows Phone 7中的应用程序。在该应用程序中,我已经完成了超过30个屏幕。现在我想在所有页面中添加滑动菜单。

请允许我在所有页面中添加滑动菜单。

我试过WindowsPhoneControl。我创建了一个带有列表框的菜单,我尝试添加所有页面。

用户控制页面: -

<UserControl x:Class="NewExample.SlidingMenu"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    d:DesignHeight="768" d:DesignWidth="400">
      <Grid x:Name="LayoutRoot" Background="#FFB4B4B4">
            <Button Command="{Binding testButton1}" Content="Test Button 1" Height="72" HorizontalAlignment="Left" Margin="12,10,0,0" Name="button1" VerticalAlignment="Top" Width="376" />
            <Button Command="{Binding testButton2}" Content="Test Button 2" Height="72" HorizontalAlignment="Left" Margin="12,72,0,0" Name="button2" VerticalAlignment="Top" Width="376" />
            <Button Command="{Binding testButton3}" Content="Test Button 3" Height="72" HorizontalAlignment="Left" Margin="12,132,0,0" Name="button3" VerticalAlignment="Top" Width="376" />
            <Button Command="{Binding testButton4}" Content="Test Button 4" Height="72" HorizontalAlignment="Left" Margin="12,196,0,0" Name="button4" VerticalAlignment="Top" Width="376" />
        </Grid>
    </UserControl>

页: -

 <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--ContentPanel -  place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="{Binding gridMargin}">

            <Button Command="{Binding slideButton}" Content="Slide" Height="70" Name="slideButton" Width="160" HorizontalAlignment="Left" VerticalAlignment="Top" />
            <ScrollViewer Margin="0,80,0,100">
                <StackPanel Orientation="Vertical">
                    <TextBlock Text="Index Page 3" FontSize="28" HorizontalAlignment="Center" VerticalAlignment="Stretch" />
                    <Button Width="476" Command="{Binding getPageStackButton}" Content="Get Pages From PageStack" Height="72" HorizontalAlignment="Left" Margin="5,0,0,0" Name="button12" VerticalAlignment="Bottom" />
                    <Button Command="{Binding messageBoxExampleButton}" Content="Message Box Example" Height="72" Name="button1" Width="476" />
                    <Button Command="{Binding orderDetailButton}" Content="Order Detail" Height="72" Name="button3" Width="476" />
                    <Button Command="{Binding customMessageButton}" Content="Custom Message Box" Height="72" Name="button2" Width="476" />

                </StackPanel>
            </ScrollViewer>
            <local:BottomTabBar Margin="0,660,0,0"/>                
            <Grid x:Name="SettingsPane" Width="400"
             Margin="{Binding slideMargin}"
             Grid.Row="0">
                <local:SlidingMenu Width="400" Margin="0,0,0,0" />
            </Grid> 
        </Grid>
    </Grid>

我只是在单击页面中的滑块按钮时更改slideMenu和页面的边距。

但它不像滑动菜单那样工作。请告诉我任何其他想法。

2 个答案:

答案 0 :(得分:0)

这可能不是最好的方法,但很容易。

如果您希望菜单从底部滑入,请将XAML更改为类似的内容:

<NewExample:SlidingMenu x:Name="ucMain"Height="500" VerticalAlignment="Bottom" Margin="0,0,0,-500"/>

添加对System.Windows.Threading的引用。

向页面添加一个Loaded事件:

private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
    SlideIn();
}

其余代码:

private void SlideIn()
    {
        DispatcherTimer timerMenuIn = new DispatcherTimer();
        timerMenuIn.Interval = new TimeSpan(0, 0, 0, 0, 1);
        timerMenuIn.Tick += timerMenuIn_Tick;
        timerMenuIn.Start();
    }

    void timerMenuIn_Tick(object sender, EventArgs e)
    {
        int speed = 7;
        if (ucMain.Margin.Bottom >= -speed)
        {
            ucMain.Margin = new Thickness(
            ucMain.Margin.Left,
            ucMain.Margin.Top,
            ucMain.Margin.Right, 0);
            ((DispatcherTimer)sender).Stop();
        }
        else
        {
            ucMain.Margin = new Thickness(
            ucMain.Margin.Left,
            ucMain.Margin.Top,
            ucMain.Margin.Right,
            ucMain.Margin.Bottom + speed);
        }
    }

您可以通过更改其他边距值轻松更改方向。希望这就是你要找的东西

答案 1 :(得分:0)

您可以下载Windows Phone Toolkit。按照“通过代码使用页面转换”部分下的说明here,您要阅读的位位于网页的中间位置。