有没有办法在新的 .net Maui 中为移动应用程序(Android、Ios 和 WinApp)创建可拖动项目的布局?
我一直在寻找该平台可以做什么,但目前还没有找到任何东西。
是的,使用CanDrag 和AllowDrop。
在这里找到它DragdropMaui 示例
在 MainPage.xaml 中
<Frame Margin="20">
<Frame.GestureRecognizers>
<DropGestureRecognizer AllowDrop="True" Drop="DropGestureRecognizer_Drop_1" />
</Frame.GestureRecognizers>
</Frame>
<Label Text="Drag Me away" HorizontalTextAlignment="Center" TextColor="Black" FontSize="36">
<Label.GestureRecognizers>
<DragGestureRecognizer CanDrag="True" DragStarting="DragGestureRecognizer_DragStarting_1" />
</Label.GestureRecognizers>
</Label>
Run Code Online (Sandbox Code Playgroud)
在 MainPage.cs 中
private void DragGestureRecognizer_DragStarting_1(object sender, DragStartingEventArgs e)
{
var label = (sender as Element)?.Parent as Label;
e.Data.Properties.Add("Text", label.Text);
}
private void DropGestureRecognizer_Drop_1(object sender, DropEventArgs e)
{
var data = e.Data.Properties["Text"].ToString();
var frame = (sender as Element)?.Parent as Frame;
frame.Content = new Label
{
Text = data
};
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6031 次 |
| 最近记录: |