gpt4 book ai didi

c# - 在哪里可以找到列表中可单击项目使用的 Windows Phone 按钮样式?

转载 作者:太空宇宙 更新时间:2023-11-03 10:50:25 26 4
gpt4 key购买 nike

在内置的 Windows Phone 应用程序中,列表(StackPanel 或 LongListSelector)中的可点击项通常具有以下行为:

  1. 当点击/点击并按住项目缩小时。
  2. 当单击/点击并按住 1 秒时,会弹出一个上下文菜单。
  3. 如果指针在按住时移动了一定数量的像素,则点击操作将中止。

在所有应用程序 View (向左滑动主屏幕时到达的屏幕)中很容易观察到该行为。因为 2.+3。已经由按钮处理,并且 1. 很容易通过按下按钮时缩小所有内容的样式来实现,我很确定列表中的项目使用样式化的按钮作为项目模板 - 样式是不同于默认的按钮样式。

我在哪里可以找到该样式?

最佳答案

根据 Pradeep 的回答,我可以解决这个问题。可点击项不是 Button,尽管也可以实现与按钮样式相同的行为(请参阅此答案的底部)。收缩时点击效果实际上是倾斜时点击效果,如果在左侧或右侧而不是中间点击项目,细心的观察者就会看到这种效果。

如果为 LongListSelector 启用了倾斜效果,则倾斜会应用于单个 LongListSelector 项目。 TiltEffect 是一个附加属性。要使用它,项目必须引用 Microsoft 的 WPtoolkit。在 nuget 上可用。

我在下面附上了代码,展示了如何在 LongListSelector 中使用 TiltEffectContextMenu。要响应对 LongListSelector 中项目的点击,请参阅 LongListSelector: Item tap? .

<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>

* 这种风格是最小的,并没有照顾到所有情况(例如禁用/启用)。

关于c# - 在哪里可以找到列表中可单击项目使用的 Windows Phone 按钮样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21616186/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com