运行时可移动矩形窗口商店应用程序
Posted
技术标签:
【中文标题】运行时可移动矩形窗口商店应用程序【英文标题】:runtime Movable rectangle windows store app 【发布时间】:2015-11-17 01:21:59 【问题描述】:我正在尝试创建将通过鼠标拖动移动的运行时间矩形。由于某种原因,代码无法正常工作。
private void Rectangle_Click(object sender, RoutedEventArgs e)
var rec = new Rectangle();
rec.Height = 100;
rec.Width = 100;
rec.Fill = new SolidColorBrush(Colors.Violet);
rec.ManipulationDelta += rec_ManipulationDelta;
board.Children.Add(rec);
void rec_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
dragTranslation.X += e.Delta.Translation.X;
dragTranslation.Y += e.Delta.Translation.Y;
dragTranslation = new TranslateTransform();
this.RenderTransform = this.dragTranslation;
【问题讨论】:
【参考方案1】:问题出在分配变换时。试试
private void Rectangle_Click(object sender, RoutedEventArgs e)
var rec = new Rectangle();
rec.Height = 100;
rec.Width = 100;
rec.Fill = new SolidColorBrush(Colors.Violet);
rec.ManipulationMode=ManipulationModes.All;
rec.ManipulationDelta += rec_ManipulationDelta;
rec.RenderTransform=new TranslateTransform(); // Create new TranslateTransform and assign to the rectangle
board.Children.Add(rec);
void rec_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
Rectangle recSender = (Rectangle) sender; // Get the Rectangle
TranslateTransform ttSender = recSender.RenderTransform as TranslateTransform; // Get the Rectangle's RenderTransform (which is a TranslateTransform)
ttSender.X += e.Delta.Translation.X;
ttSender.Y += e.Delta.Translation.Y;
【讨论】:
以上是关于运行时可移动矩形窗口商店应用程序的主要内容,如果未能解决你的问题,请参考以下文章
基于 Django + Celery 的应用程序的动态(即运行时可配置)日志配置