首页 新闻 会员 周边 捐助

WPF 动态生成Popup

0
悬赏园豆:50 [已关闭问题] 关闭于 2011-07-05 16:42

我在代码中动态生成了一个Popup控件,当鼠标点击Label时触发Popup弹出,但是当鼠标左键弹起时Popup马上消失,不会停留,而我在Xaml中实现时会停留一段时间,直到鼠标点击其他地方(其中StaysOpen=false)因为我发现当StaysOpen=true时,每点击一次Label会弹出一个新的Popup。以下是我们的代码:

(Xaml实现代码)

View Code
1 <Grid>
2 <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="239,106,0,0" Name="button1"
3 VerticalAlignment="Top" Width="75" Click="button1_Click" />
4 <Popup Name="myPopup" AllowsTransparency="True" StaysOpen="False"
5 PopupAnimation="Fade" Placement="Mouse">
6 <Border BorderBrush="Beige" BorderThickness="1">
7 <TextBlock Name="myPopupText" Width="150" Background="LightBlue"
8 Foreground="Blue" TextWrapping="Wrap" />
9 </Border>
10 </Popup>
11 </Grid>

(C#代码,有问题)

View Code
1 private void show_MouseLeftButtonDown(object sender, MouseButtonEventArgs args)
2 {
3 showCondition show = new showCondition();
4 show.Background = Brushes.Beige;
5
6 Popup myPopup = new Popup();
7 myPopup.AllowsTransparency = false;
8 myPopup.PopupAnimation = PopupAnimation.Fade;
9 myPopup.StaysOpen = false;
10 myPopup.PlacementTarget = (Label)sender;
11
12 myPopup.Child = show;
13 myPopup.Placement = PlacementMode.Mouse;
14
15 myPopup.IsOpen = true;
16 }
骑驴过赵桥的主页 骑驴过赵桥 | 初学一级 | 园豆:150
提问于:2011-06-29 09:53
< >
分享
所有回答(1)
0

要的就是这个!谢谢

绝版佳嫐 | 园豆:204 (菜鸟二级) | 2021-09-04 00:05
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册