在内置的Windows Phone应用程序中,列表中的可单击项目(StackPanel或LonglistSelector)通常具有以下行为:
- 单击/敲击并保持项目收缩时。
- 单击/敲击和持有1秒时,上下文菜单会弹出。
- 如果指针在保持时被一定量的像素移动,则TAP操作被中止。
在所有应用程序视图中很容易观察到该行为(当您在左侧刷新主屏幕时,您可以到达的屏幕)。因为2. 3。已经通过按钮照顾了。与默认按钮样式不同。
我在哪里找到该样式?
基于Pradeep的答案,我可以解决这个问题。可单击的项目不是Button
s,也可以实现与按钮样式相同的行为(请参阅此答案的底部)。当敲击效果实际上是一种倾斜效果时,收缩的效果是一种倾斜效果,如果物品在左侧或右侧而不是中间的左右挖掘,则仔细观察者可以看到。
如果对LongListSelector
启用了倾斜效果,则倾斜度适用于单个LongListSelector
项目。TiltEffect
是一个附件。要使用它,该项目必须引用Nuget上可用的Microsoft的WPToolKit。
我在下面附加了代码,该代码显示了如何在LongListSelector
中使用TiltEffect
和ContextMenu
。要对LongListSelector
中的项目的点击做出反应,请参见LonglistSelector:项目点击?
<phone:PhoneApplicationPage
x:Class="Test.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit">
<Grid x:Name="LayoutRoot">
<phone:LongListSelector ItemsSource="{Binding Items}" toolkit:TiltEffect.IsTiltEnabled="True">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding}" Style="{StaticResource PhoneTextLargeStyle}"/>
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu>
<toolkit:MenuItem Header="delete"/>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
</StackPanel>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
</Grid>
</phone:PhoneApplicationPage>
另外,外观和行为相同的按钮样式可以通过相同的附件属性实现,或多或少*这样*:
<Style x:Key="ListButton" TargetType="Button">
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilyLight}" />
<Setter Property="FontSize" Value="{StaticResource PhoneFontSizeLarge}" />
<!-- Transparent background is necessary to be part of hitbox. transparent background and null background behave differently -->
<Setter Property="Background" Value="Transparent" />
<Setter Property="Padding" Value="0" />
<Setter Property="toolkit:TiltEffect.IsTiltEnabled" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border BorderThickness="{TemplateBinding BorderThickness}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}">
<ContentPresenter Content="{TemplateBinding Content}" Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
*此样式很小,并且不照顾所有情况(例如禁用/启用)。
您可以从这些给定链接下载演示应用:
倾斜效果的链接在这里
上下文菜单的链接这里