我正在创建 UWP 应用程序,我需要在滑动菜单中显示一系列结果。滑动菜单可滚动并且可以滑动改变其高度就像 Windows 10 Mobile 中的地图应用程序中的搜索结果一样。
我找不到任何教程来创建这样的体验。
提前致谢
您也可以使用UserControl
去做这个。
XAML:
<ScrollViewer x:Name="scrollViewer" HorizontalAlignment="Stretch" ScrollViewer.VerticalScrollMode="Disabled" VerticalScrollBarVisibility="Hidden">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="20" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Border x:Name="Area1" Grid.Row="0" Height="{x:Bind childheight}" HorizontalAlignment="Stretch" Background="AliceBlue"></Border>
<Grid x:Name="SlidButton" Background="Gray" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Grid.Row="1"
ManipulationStarted="SlidButton_ManipulationStarted" ManipulationCompleted="SlidButton_ManipulationCompleted"
ManipulationMode="All" ManipulationDelta="SlidButton_ManipulationDelta">
<TextBlock Text="" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="Black" FontFamily="Segoe MDL2 Assets" FontSize="15" />
</Grid>
<Border x:Name="Area2" Grid.Row="2" Height="{x:Bind childheight}" HorizontalAlignment="Stretch" Background="Transparent"></Border>
</Grid>
</ScrollViewer>
后面的代码:
private double height;
private double childheight;
public SlidableView()
{
this.InitializeComponent();
height = Window.Current.Bounds.Height * 2 - 40;
childheight = Window.Current.Bounds.Height - 40;
}
private void SlidButton_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
{
scrollViewer.VerticalScrollMode = ScrollMode.Enabled;
}
private void SlidButton_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
{
scrollViewer.VerticalScrollMode = ScrollMode.Disabled;
}
private static double Y;
private void SlidButton_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
Y = Y + e.Delta.Translation.Y;
scrollViewer.ChangeView(null, -Y, null);
}
这是一个非常简单的移动版本,当它应用于PC时,请更改“height”和“childheight”,如下所示:
height = Window.Current.Bounds.Height * 2 - 20;
childheight = Window.Current.Bounds.Height - 20;
当我说这是一个非常简单的版本时,因为我没有公开此用户控件的任何属性,所以您可以公开两个的两个子属性Border
正如我上次回答中那样进行控制。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)