应该适用于矩形元素移动,改变大小或折叠/扩展.
public class ControltouchTracker{ private List<FrameworkElement> controls = new List<FrameworkElement>(); private Dictionary<FrameworkElement,ControlRegion> controlBounds = new Dictionary<FrameworkElement,ControlRegion>(); public ControltouchTracker(FrameworkElement rootElement) { rootElement.LayoutUpdated += this.OnLayoutUpdated; } public voID RegisterControl(FrameworkElement control) { controls.Add(control); } public voID RemoveControl(FrameworkElement control) { controls.Remove(control); controlBounds.Remove(control); } private voID OnLayoutUpdated(object sender,EventArgs e) { foreach (Control control in this.controls) { this.RefreshControlBounds(control); } } private voID RefreshControlBounds(FrameworkElement control) { if (this.ControlisVisible(control)) { try { Generaltransform controltransform = control.transformToVisual(Application.Current.RootVisual); Point offset = controltransform.transform(new Point(0,0)); this.controlBounds[control] = new ControlRegion { left = (float)offset.X,Right = (float)(offset.X + control.ActualWIDth),top = (float)offset.Y,Bottom = (float)(offset.Y + control.ActualHeight) }; } catch (ArgumentException) { } } else { if (this.controlBounds.ContainsKey(control)) { this.controlBounds.Remove(control); } } } private bool ControlisVisible(FrameworkElement control) { // End case if (control == null) { return true; } if (control.Visibility == Visibility.Collapsed) { return false; } return this.ControlisVisible(control.Parent as FrameworkElement); } public bool touchesControl(Vector2 touchposition) { foreach (ControlRegion region in this.controlBounds.Values) { if (touchposition.X >= region.left && touchposition.X <= region.Right && touchposition.Y >= region.top && touchposition.Y <= region.Bottom) { return true; } } return false; } public class ControlRegion { public float left { get; set; } public float Right { get; set; } public float top { get; set; } public float Bottom { get; set; } }}
(编辑)更新了使用父元素更改可见性的示例.
总结以上是内存溢出为你收集整理的WP7:在Silverlight处理时抑制XNA触摸输入?全部内容,希望文章能够帮你解决WP7:在Silverlight处理时抑制XNA触摸输入?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)