爲了您的需求,您可以通過使用ManipulationDelta
類移動在縱軸上的按鈕。你可以用下面的代碼來實現它。 更多請參考Handle pointer input。這裏是official code樣本。
MainPage::MainPage()
{
InitializeComponent();
InitManipulationTransforms();
btnMove->ManipulationDelta += ref new ManipulationDeltaEventHandler(this, &MainPage::btnMove_ManipulationDelta);
btnMove->ManipulationMode = ManipulationModes::TranslateX;
}
void App14::MainPage::InitManipulationTransforms()
{
transforms = ref new TransformGroup();
previousTransform = ref new MatrixTransform();
previousTransform->Matrix = Matrix::Identity;
deltaTransform = ref new CompositeTransform();
transforms->Children->Append(previousTransform);
transforms->Children->Append(deltaTransform);
// Set the render transform on the rect
btnMove->RenderTransform = transforms;
}
void App14::MainPage::btnMove_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
}
void MainPage::btnMove_ManipulationDelta(Platform::Object^ sender, ManipulationDeltaRoutedEventArgs^ e)
{
previousTransform->Matrix = transforms->Value;
// Get center point for rotation
Point center = previousTransform->TransformPoint(Point(e->Position.X, e->Position.Y));
deltaTransform->CenterX = center.X;
deltaTransform->CenterY = center.Y;
// Look at the Delta property of the ManipulationDeltaRoutedEventArgs to retrieve
// the rotation, scale, X, and Y changes
deltaTransform->Rotation = e->Delta.Rotation;
deltaTransform->TranslateX = e->Delta.Translation.X;
deltaTransform->TranslateY = e->Delta.Translation.Y;
}
你可以通過修改按鈕ManipulationMode
更改按鈕的滾動方向。
btnMove->ManipulationMode = ManipulationModes::TranslateY;
非常感謝,這是工作的罰款。但我仍然有一個問題。有了這段代碼,按鈕就可以脫離實體邊界,然後你就不能讓他回來,他會在邊界後面打勾。我該如何解決 ?我如何設置邊界? – David
willouble height =(dynamic_cast(Window :: Current-> Content)) - > ActualHeight; ' 我聲明瞭框架的當前高度,在代碼中的確切位置是否放置了之前發佈的if結構? –
David