【问题标题】:Windows Phone 7 Sliding MenuWindows Phone 7 滑动菜单
【发布时间】:2014-07-29 09:22:13
【问题描述】:

我正在 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 和页面的边距。

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

【问题讨论】:

    标签: windows-phone-7 slidingmenu


    【解决方案1】:

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

    如果您希望菜单从底部滑入,请将 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);
            }
        }
    

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 2014-12-15
        • 1970-01-01
        • 1970-01-01
        • 2011-05-23
        • 1970-01-01
        • 2011-10-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多