c# - 禁用 SwipeView 滑动选项
问题描述
我在我的项目中使用 SwipeView 来显示和隐藏页面左侧的侧边菜单。现在我想通过点击按钮而不是滑动页面来打开和隐藏菜单。到目前为止,我想出了如何通过点击按钮来打开和隐藏菜单,但我没有找到解决方案来解决如何禁用打开菜单的滑动。
知道如何以正确的方式做到这一点吗?
这是我实现滑动和敲击效果的代码。
这是 xaml.cs 中的代码:
private async void OpenAnimation()
{
await swipeContent.ScaleYTo(0.9, 300, Easing.SinOut);
}
private async void CloseAnimation()
{
await swipeContent.RotateTo(0, 300, Easing.SinOut);
}
private void OpenSwipe(object sender, EventArgs e)
{
MainSwipeView.Open(OpenSwipeItem.LeftItems);
OpenAnimation();
}
private void CloseSwipe(object sender, EventArgs e)
{
MainSwipeView.Close();
CloseAnimation();
}
private void SwipeStarted(object sender, SwipeStartedEventArgs e)
{
OpenAnimation();
}
private void SwipeEnded(object sender, SwipeEndedEventArgs e)
{
if (!e.IsOpen)
CloseAnimation();
}
这是 xaml 中的代码
<SwipeView x:Name="MainSwipeView" BackgroundColor="Transparent"
SwipeStarted="SwipeStarted" SwipeEnded="SwipeEnded">
谢谢。
解决方案
您可以将该IsEnabled
属性设置为 false 以禁用滑动。
xml:
<StackLayout HorizontalOptions="Center" VerticalOptions="CenterAndExpand">
<SwipeView IsEnabled="False">
<SwipeView.LeftItems>
<SwipeItems>
<SwipeItem
BackgroundColor="LightGreen"
IconImageSource="grapes_24.png"
Invoked="Favorite_Invoked"
Text="Favorite" />
<SwipeItem
BackgroundColor="LightPink"
IconImageSource="star_small.png"
Invoked="Delete_Invoked"
Text="Delete" />
</SwipeItems>
</SwipeView.LeftItems>
<Grid
BackgroundColor="LightGray"
HeightRequest="60"
WidthRequest="300">
<Label
HorizontalOptions="Center"
Text="Swipe right"
VerticalOptions="Center" />
</Grid>
</SwipeView>
</StackLayout>
推荐阅读
- discord - Discord.js Userinfo 命令类型错误:无法读取 null 的属性“角色”
- ios - iOS 模拟器在 macOS Monterey 上崩溃
- sqlite - Sqlite 语句 "DELETE FROM
如果存在 " 在 "IF" 附近不断出现语法错误 - apache - 如何在 apache 服务器上配置 httpd-vhost.conf 文件以全局运行我的 namecheap 域?
- python - KeyError:使用 fcswrite 库时出现“'FCS 格式'”
- python - CSV:如何将列添加到列表并从另一个列表中找到最佳匹配(最接近的值)?
- ag-grid - setRowData 后的 Ag-Grid 事件和所有单元格都已呈现
- magento - Magento 2更改静态内容文件夹
- node.js - 如何回到 nodejs 中的 shell:最新的 docker 镜像?
- plot - 同一轴上的两个图 \addplot3 (pgfplots)