Windows phone 7 WP7弹出窗口未显示
在我的应用程序中,当用户单击图像时,我想在弹出窗口中显示一个简单的字符串。为此,我在图像中添加了一个Windows phone 7 WP7弹出窗口未显示,windows-phone-7,popup,Windows Phone 7,Popup,在我的应用程序中,当用户单击图像时,我想在弹出窗口中显示一个简单的字符串。为此,我在图像中添加了一个点击手势侦听器,在处理程序中,我有以下代码: private void GestureListener_Tap( object sender, GestureEventArgs e ) { var img = sender as Image; if( img == null ) { return; } Point pos = e.GetPosition( img );
点击手势侦听器,在处理程序中,我有以下代码:
private void GestureListener_Tap( object sender, GestureEventArgs e )
{
var img = sender as Image;
if( img == null ) {
return;
}
Point pos = e.GetPosition( img );
string text = "I'm a popup!";
var popup = new Popup() {
Child = new Border() {
BorderBrush = new SolidColorBrush( Colors.LightGray ),
Child = new TextBlock() {
Text = text,
TextWrapping = TextWrapping.Wrap,
},
},
HorizontalAlignment = HorizontalAlignment.Stretch,
HorizontalOffset = pos.X,
VerticalOffset = pos.Y,
Visibility = Visibility.Visible,
};
popup.IsOpen = true;
Debug.WriteLine( "GestureListener_Tap: " + text );
}
调用WriteLine
会在调试器输出窗口中打印,但不会显示弹出窗口。我做错了什么
谢谢你的帮助 我尝试了你的代码,弹出窗口显示出来。我认为您的问题是图像相对于鼠标的位置。尝试为父容器设置另一个背景,我想您会看到弹出窗口。你也可以试着和我一起玩
Point pos = e.GetPosition(null);
在获得所需位置之前您是否验证了图像的坐标?也许你在屏幕外找到了一个很好的位置?是的,就是这样,它被渲染到了我没想到的地方。加上文字是黑色的,背景也是黑色的!我最终使用了pointpos=e.GetPosition(LayoutRoot)代码>@Praetorian:是的,黑对黑的问题正是我尝试时遇到的:)