gpt4 book ai didi

c# - 在 Windows 8 Metro App 中拖放图像

转载 作者:行者123 更新时间:2023-11-30 19:06:12 26 4
gpt4 key购买 nike

有没有办法在 Windows 8 Metro 应用程序中拖放图像。我正在使用 C# 和 XAML。以下是我需要的...

enter image description here

最佳答案

当然有。你必须自己控制它,但这很容易。您需要像这样使用一些指针事件:

XAML:

<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}"   PointerMoved="GridPointerMoved">
<Image x:Name="image1" HorizontalAlignment="Left" Height="100" VerticalAlignment="Top" Width="100" Source="Assets/imageFile.png" PointerPressed="ImagePointerPressed" PointerReleased="ImagePointerReleased"/>
</Grid>

然后在你的 CS 文件中:

Point positionWithinImage;
private void ImagePointerPressed(object sender, PointerRoutedEventArgs e)
{
Debug.WriteLine("Pressed");
holding = true;

positionWithinImage = e.GetCurrentPoint(sender as Image).Position;
}

private void ImagePointerReleased(object sender, PointerRoutedEventArgs e)
{
Debug.WriteLine("Released");
holding = false;
}

bool holding = false;

private void GridPointerMoved(object sender, PointerRoutedEventArgs e)
{
if (holding)
{
var pos = e.GetCurrentPoint(image1.Parent as Grid).Position;
image1.Margin = new Thickness(pos.X - this.positionWithinImage.X, pos.Y - this.positionWithinImage.Y, 0, 0);
}
}

关于c# - 在 Windows 8 Metro App 中拖放图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13000587/

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