Windows Phone 8.1アプリケーションを構築していますが、Androidアプリのようなサイドバーが必要です。どうすればいいですか?
この例を試しましたが、コンパイルされず、操作イベントが発生しません。
これは、速度処理を使用した非常に単純な例です。
グリッドのManipulation
プロパティをに設定してください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();
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加