我在代码中动态生成了一个Popup控件,当鼠标点击Label时触发Popup弹出,但是当鼠标左键弹起时Popup马上消失,不会停留,而我在Xaml中实现时会停留一段时间,直到鼠标点击其他地方(其中StaysOpen=false)因为我发现当StaysOpen=true时,每点击一次Label会弹出一个新的Popup。以下是我们的代码:
(Xaml实现代码)
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#代码,有问题)
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 }
要的就是这个!谢谢