var tileMore = new Tile
{
Height = 40,
Width = 85,
Background = new SolidColorBrush(Color.FromRgb(120, 240, 120)),
Title = "更多...",
};
tileMore.SetResourceReference(FrameworkElement.StyleProperty, "KentTile");
Popup popup = new Popup
{
//StaysOpen = false,
PopupAnimation = PopupAnimation.Slide,
PlacementTarget = tileMore,
Placement = PlacementMode.Bottom,
AllowsTransparency = true
};
//pop里面生成的内容,本例是StackPannel中包括一个textbox
WrapPanel stackPanel = new WrapPanel
{
Width = tileMore.Width * 5,
Background = Brushes.Transparent
};
stackPanel.Children.Add(/*sth to show*/);
popup.Child = stackPanel;
tileMore.MouseEnter += (sender, e) =>
{
popup.IsOpen = true;
};
tileMore.MouseLeave += (s, e) =>
{
if (timerCloseRecentPopup == null)
{
timerCloseRecentPopup = new DispatcherTimer();
timerCloseRecentPopup.Interval = new TimeSpan(0, 0, 1);
timerCloseRecentPopup.Tag = popup;
timerCloseRecentPopup.Tick += closePopup;
}
timerCloseRecentPopup.Stop();
timerCloseRecentPopup.Start();
};
popup.MouseLeave += (s, e) =>
{
if(timerCloseRecentPopup == null)
{
timerCloseRecentPopup = new DispatcherTimer();
timerCloseRecentPopup.Interval = new TimeSpan(0, 0, 1);
timerCloseRecentPopup.Tag = popup;
timerCloseRecentPopup.Tick += closePopup;
}
timerCloseRecentPopup.Stop();
timerCloseRecentPopup.Start();
};