C# 在Windows Phone 8.1应用程序中添加侧栏

C# 在Windows Phone 8.1应用程序中添加侧栏,c#,windows-phone-8.1,win-universal-app,C#,Windows Phone 8.1,Win Universal App,我正在构建WindowsPhone8.1应用程序,我想要一个类似android应用程序的侧栏。我怎么做 我尝试了这个示例,但没有编译,操纵事件的Dot fire也没有启动。这里是一个非常简单的velocity处理示例 确保将网格的操纵属性设置为All 将网格背景从DarkSalmon更改为Transparent XAML <Canvas Name="RootCanvas"> <Canvas.Resources> <Storyboard x:

我正在构建WindowsPhone8.1应用程序,我想要一个类似android应用程序的侧栏。我怎么做


我尝试了这个示例,但没有编译,操纵事件的Dot fire也没有启动。

这里是一个非常简单的velocity处理示例

确保将网格的
操纵
属性设置为
All

将网格背景从
DarkSalmon
更改为
Transparent

XAML

<Canvas Name="RootCanvas">
    <Canvas.Resources>
        <Storyboard x:Name="MoveAnimation">
            <DoubleAnimation Duration="0:0:0.2" To="0" Storyboard.TargetProperty="(Canvas.Left)" Storyboard.TargetName="Sidebar" d:IsOptimized="True" />
        </Storyboard>
    </Canvas.Resources>

    <Grid Name="Sidebar" Background="DarkSalmon" Width="360" Height="640" Canvas.Left="-340" ManipulationDelta="Sidebar_ManipulationDelta" ManipulationMode="All" ManipulationCompleted="Sidebar_ManipulationCompleted">
        <Grid Background="DarkSlateBlue" Margin="0,0,20,0">
            <StackPanel Orientation="Vertical">
                <Button Content="Mailbox" />
                <Button Content="Calendar" />
                <Button Content="Tasks" />
                <Button Content="Documents" />
            </StackPanel>
        </Grid>
    </Grid>
</Canvas>

代码隐藏

private bool _triggerCompleted;

    private const double SideMenuCollapsedLeft = -340;
    private const double SideMenuExpandedLeft = 0;

    private void Sidebar_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
    {
        _triggerCompleted = true;

        double finalLeft = Canvas.GetLeft(Sidebar) + e.Delta.Translation.X;
        if (finalLeft < -340 || finalLeft > 0)
            return;

        Canvas.SetLeft(Sidebar, finalLeft);

        if (e.IsInertial && e.Velocities.Linear.X > 1)
        {
            _triggerCompleted = false;
            e.Complete();
            MoveLeft(SideMenuExpandedLeft);
        }

        if (e.IsInertial && e.Velocities.Linear.X < -1)
        {
            _triggerCompleted = false;
            e.Complete();
            MoveLeft(SideMenuCollapsedLeft);
        }

        if (e.IsInertial && Math.Abs(e.Velocities.Linear.X) <= 1)
            e.Complete();
    }

    private void Sidebar_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
    {
        if (_triggerCompleted == false)
            return;

        double finalLeft = Canvas.GetLeft(Sidebar);

        if (finalLeft > -170)
            MoveLeft(SideMenuExpandedLeft);
        else
            MoveLeft(SideMenuCollapsedLeft);
    }

    private void MoveLeft(double left)
    {
        double finalLeft = Canvas.GetLeft(Sidebar);

        Storyboard moveAnivation = ((Storyboard)RootCanvas.Resources["MoveAnimation"]);
        DoubleAnimation direction = ((DoubleAnimation)((Storyboard)RootCanvas.Resources["MoveAnimation"]).Children[0]);

        direction.From = finalLeft;

        moveAnivation.SkipToFill();

        direction.To = left;

        moveAnivation.Begin();
    }
private bool\u触发器已完成;
private const双边菜单collapsedleft=-340;
private const双边函数expandedleft=0;
私有void边栏_操纵delta(对象发送方,操纵deltaroutedventargs e)
{
_triggerCompleted=true;
double finalLeft=Canvas.GetLeft(边栏)+e.Delta.Translation.X;
如果(最终英尺<-340 | |最终英尺>0)
返回;
Canvas.SetLeft(边栏,finalLeft);
如果(e.i能量和e.e速度.Linear.X>1)
{
_triggerCompleted=false;
e、 完全();
向左移动(侧菜单Expandedleft);
}
if(e.i能量和e.e速度。线性X<-1)
{
_triggerCompleted=false;
e、 完全();
向左移动(侧菜单左对齐);
}
if(e.i能量和数学Abs(e.velociations.Linear.X)-170)
向左移动(侧菜单Expandedleft);
其他的
向左移动(侧菜单左对齐);
}
私有空间左移(双左)
{
double finalLeft=Canvas.GetLeft(侧边栏);
情节提要MoveAnimation=((情节提要)RootCanvas.Resources[“MoveAnimation”]);
DoubleAnimation方向=((DoubleAnimation)((故事板)RootCanvas.Resources[“MoveAnimation”]).Children[0]);
方向。从=最终英尺;
moveAnivation.SkipToFill();
方向。到=左;
moveAnivation.Begin();
}

这是一个非常简单的速度处理示例

确保将网格的
操纵
属性设置为
All

将网格背景从
DarkSalmon
更改为
Transparent

XAML

<Canvas Name="RootCanvas">
    <Canvas.Resources>
        <Storyboard x:Name="MoveAnimation">
            <DoubleAnimation Duration="0:0:0.2" To="0" Storyboard.TargetProperty="(Canvas.Left)" Storyboard.TargetName="Sidebar" d:IsOptimized="True" />
        </Storyboard>
    </Canvas.Resources>

    <Grid Name="Sidebar" Background="DarkSalmon" Width="360" Height="640" Canvas.Left="-340" ManipulationDelta="Sidebar_ManipulationDelta" ManipulationMode="All" ManipulationCompleted="Sidebar_ManipulationCompleted">
        <Grid Background="DarkSlateBlue" Margin="0,0,20,0">
            <StackPanel Orientation="Vertical">
                <Button Content="Mailbox" />
                <Button Content="Calendar" />
                <Button Content="Tasks" />
                <Button Content="Documents" />
            </StackPanel>
        </Grid>
    </Grid>
</Canvas>

代码隐藏

private bool _triggerCompleted;

    private const double SideMenuCollapsedLeft = -340;
    private const double SideMenuExpandedLeft = 0;

    private void Sidebar_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
    {
        _triggerCompleted = true;

        double finalLeft = Canvas.GetLeft(Sidebar) + e.Delta.Translation.X;
        if (finalLeft < -340 || finalLeft > 0)
            return;

        Canvas.SetLeft(Sidebar, finalLeft);

        if (e.IsInertial && e.Velocities.Linear.X > 1)
        {
            _triggerCompleted = false;
            e.Complete();
            MoveLeft(SideMenuExpandedLeft);
        }

        if (e.IsInertial && e.Velocities.Linear.X < -1)
        {
            _triggerCompleted = false;
            e.Complete();
            MoveLeft(SideMenuCollapsedLeft);
        }

        if (e.IsInertial && Math.Abs(e.Velocities.Linear.X) <= 1)
            e.Complete();
    }

    private void Sidebar_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
    {
        if (_triggerCompleted == false)
            return;

        double finalLeft = Canvas.GetLeft(Sidebar);

        if (finalLeft > -170)
            MoveLeft(SideMenuExpandedLeft);
        else
            MoveLeft(SideMenuCollapsedLeft);
    }

    private void MoveLeft(double left)
    {
        double finalLeft = Canvas.GetLeft(Sidebar);

        Storyboard moveAnivation = ((Storyboard)RootCanvas.Resources["MoveAnimation"]);
        DoubleAnimation direction = ((DoubleAnimation)((Storyboard)RootCanvas.Resources["MoveAnimation"]).Children[0]);

        direction.From = finalLeft;

        moveAnivation.SkipToFill();

        direction.To = left;

        moveAnivation.Begin();
    }
private bool\u触发器已完成;
private const双边菜单collapsedleft=-340;
private const双边函数expandedleft=0;
私有void边栏_操纵delta(对象发送方,操纵deltaroutedventargs e)
{
_triggerCompleted=true;
double finalLeft=Canvas.GetLeft(边栏)+e.Delta.Translation.X;
如果(最终英尺<-340 | |最终英尺>0)
返回;
Canvas.SetLeft(边栏,finalLeft);
如果(e.i能量和e.e速度.Linear.X>1)
{
_triggerCompleted=false;
e、 完全();
向左移动(侧菜单Expandedleft);
}
if(e.i能量和e.e速度。线性X<-1)
{
_triggerCompleted=false;
e、 完全();
向左移动(侧菜单左对齐);
}
if(e.i能量和数学Abs(e.velociations.Linear.X)-170)
向左移动(侧菜单Expandedleft);
其他的
向左移动(侧菜单左对齐);
}
私有空间左移(双左)
{
double finalLeft=Canvas.GetLeft(侧边栏);
情节提要MoveAnimation=((情节提要)RootCanvas.Resources[“MoveAnimation”]);
DoubleAnimation方向=((DoubleAnimation)((故事板)RootCanvas.Resources[“MoveAnimation”]).Children[0]);
方向。从=最终英尺;
moveAnivation.SkipToFill();
方向。到=左;
moveAnivation.Begin();
}

这是一个非常简单的速度处理示例

确保将网格的
操纵
属性设置为
All

将网格背景从
DarkSalmon
更改为
Transparent

XAML

<Canvas Name="RootCanvas">
    <Canvas.Resources>
        <Storyboard x:Name="MoveAnimation">
            <DoubleAnimation Duration="0:0:0.2" To="0" Storyboard.TargetProperty="(Canvas.Left)" Storyboard.TargetName="Sidebar" d:IsOptimized="True" />
        </Storyboard>
    </Canvas.Resources>

    <Grid Name="Sidebar" Background="DarkSalmon" Width="360" Height="640" Canvas.Left="-340" ManipulationDelta="Sidebar_ManipulationDelta" ManipulationMode="All" ManipulationCompleted="Sidebar_ManipulationCompleted">
        <Grid Background="DarkSlateBlue" Margin="0,0,20,0">
            <StackPanel Orientation="Vertical">
                <Button Content="Mailbox" />
                <Button Content="Calendar" />
                <Button Content="Tasks" />
                <Button Content="Documents" />
            </StackPanel>
        </Grid>
    </Grid>
</Canvas>

代码隐藏

private bool _triggerCompleted;

    private const double SideMenuCollapsedLeft = -340;
    private const double SideMenuExpandedLeft = 0;

    private void Sidebar_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
    {
        _triggerCompleted = true;

        double finalLeft = Canvas.GetLeft(Sidebar) + e.Delta.Translation.X;
        if (finalLeft < -340 || finalLeft > 0)
            return;

        Canvas.SetLeft(Sidebar, finalLeft);

        if (e.IsInertial && e.Velocities.Linear.X > 1)
        {
            _triggerCompleted = false;
            e.Complete();
            MoveLeft(SideMenuExpandedLeft);
        }

        if (e.IsInertial && e.Velocities.Linear.X < -1)
        {
            _triggerCompleted = false;
            e.Complete();
            MoveLeft(SideMenuCollapsedLeft);
        }

        if (e.IsInertial && Math.Abs(e.Velocities.Linear.X) <= 1)
            e.Complete();
    }

    private void Sidebar_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
    {
        if (_triggerCompleted == false)
            return;

        double finalLeft = Canvas.GetLeft(Sidebar);

        if (finalLeft > -170)
            MoveLeft(SideMenuExpandedLeft);
        else
            MoveLeft(SideMenuCollapsedLeft);
    }

    private void MoveLeft(double left)
    {
        double finalLeft = Canvas.GetLeft(Sidebar);

        Storyboard moveAnivation = ((Storyboard)RootCanvas.Resources["MoveAnimation"]);
        DoubleAnimation direction = ((DoubleAnimation)((Storyboard)RootCanvas.Resources["MoveAnimation"]).Children[0]);

        direction.From = finalLeft;

        moveAnivation.SkipToFill();

        direction.To = left;

        moveAnivation.Begin();
    }
private bool\u触发器已完成;
private const双边菜单collapsedleft=-340;
private const双边函数expandedleft=0;
私有void边栏_操纵delta(对象发送方,操纵deltaroutedventargs e)
{
_triggerCompleted=true;
double finalLeft=Canvas.GetLeft(边栏)+e.Delta.Translation.X;
如果(最终英尺<-340 | |最终英尺>0)
返回;
Canvas.SetLeft(边栏,finalLeft);
如果(e.i能量和e.e速度.Linear.X>1)
{
_triggerCompleted=false;
e、 完全();
向左移动(侧菜单Expandedleft);
}
if(e.i能量和e.e速度。线性X<-1)
{
_triggerCompleted=false;
e、 完全();
向左移动(侧菜单左对齐);
}
if(e.i能量和数学Abs(e.velociations.Linear.X)-170)
向左移动(侧菜单Expandedleft);
其他的
向左移动(侧菜单左对齐);
}
私有空间左移(双左)
{
double finalLeft=Canvas.GetLeft(侧边栏);
情节提要MoveAnimation=((情节提要)RootCanvas.Resources[“MoveAnimation”]);
DoubleAnimation方向=((DoubleAnimation)((故事板)RootCanvas.Resources[“MoveAnimation”]).Children[0]);
方向。从=最终英尺;
斯基普托夫