背水一战 Windows 10 (36) - 控件(弹出类): ToolTip, Popup, PopupMenu
2021-05-12 22:27
标签:ble c++ was nes files service 专注 iss eth [源码下载] 作者:webabcd 示例 Controls/FlyoutControl/ToolTipDemo.xaml.cs Controls/FlyoutControl/PopupDemo.xaml.cs Controls/FlyoutControl/PopupMenuDemo.xaml.cs OK 背水一战 Windows 10 (36) - 控件(弹出类): ToolTip, Popup, PopupMenu 标签:ble c++ was nes files service 专注 iss eth 原文地址:http://www.cnblogs.com/lonelyxmas/p/7567350.html
介绍
背水一战 Windows 10 之 控件(弹出类)
1、ToolTip 的示例
Controls/FlyoutControl/ToolTipDemo.xamlPage
x:Class="Windows10.Controls.FlyoutControl.ToolTipDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.Controls.FlyoutControl"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
Grid Background="Transparent">
StackPanel Margin="10 0 10 10">
TextBlock Name="textBlock1" Text="TextBlock" Margin="5"
ToolTipService.ToolTip="ToolTip 的内容"
ToolTipService.Placement="Right" />
TextBlock Name="textBlock2" Text="TextBlock" Margin="5">
ToolTipService.ToolTip>
ToolTip Content="ToolTip 的内容" Placement="Mouse"
HorizontalOffset="120" VerticalOffset="0"
Opened="toolTip_Opened" Closed="toolTip_Closed" />
ToolTipService.ToolTip>
TextBlock>
TextBlock Name="lblMsg" Margin="5" />
StackPanel>
Grid>
Page>
/*
* ToolTip - 提示框控件(继承自 ContentControl, 请参见 /Controls/BaseControl/ContentControlDemo/)
*/
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace Windows10.Controls.FlyoutControl
{
public sealed partial class ToolTipDemo : Page
{
public ToolTipDemo()
{
this.InitializeComponent();
}
private void toolTip_Opened(object sender, RoutedEventArgs e)
{
lblMsg.Text = "textBlock2 toolTip_Opened";
}
private void toolTip_Closed(object sender, RoutedEventArgs e)
{
lblMsg.Text = "textBlock2 toolTip_Closed";
}
}
}
2、Popup 的示例
Controls/FlyoutControl/PopupDemo.xamlPage
x:Class="Windows10.Controls.FlyoutControl.PopupDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.Controls.FlyoutControl"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
Grid Background="Transparent">
StackPanel Margin="10 0 10 10">
Popup Name="popup" Margin="5"
HorizontalOffset="200" VerticalOffset="10" IsLightDismissEnabled="{Binding IsChecked, ElementName=chkIsLightDismissEnabled}">
Border BorderBrush="Red" BorderThickness="1" Background="Orange" Width="200" Height="200">
StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
TextBlock Text="我是 Popup" HorizontalAlignment="Center" />
Button Name="btnClosePopup" Content="关闭" HorizontalAlignment="Center" Click="btnClosePopup_Click" />
StackPanel>
Border>
Popup.ChildTransitions>
TransitionCollection>
PopupThemeTransition />
TransitionCollection>
Popup.ChildTransitions>
Popup>
TextBlock Name="lblMsg" Margin="5" />
StackPanel Orientation="Horizontal" Margin="5">
Button Name="btnOpenPopup" Content="弹出 Popup" Click="btnOpenPopup_Click" />
CheckBox Name="chkIsLightDismissEnabled" IsChecked="False" Content="IsLightDismissEnabled" Margin="10 0 0 0" />
StackPanel>
Button Name="btnOpenPopupToast" Content="弹出仿 toast 的 Popup" Click="btnOpenPopupToast_Click" Margin="5" />
StackPanel>
Grid>
Page>
/*
* Popup - 弹出框控件(继承自 FrameworkElement, 请参见 /Controls/BaseControl/FrameworkElementDemo.xaml)
* IsOpen - 弹出框是否是打开的状态(如果要设置此属性,需要在控件加载之后)
* Opened - 弹出框打开后触发的事件
* Closed - 弹出框关闭后触发的事件
*/
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Animation;
namespace Windows10.Controls.FlyoutControl
{
public sealed partial class PopupDemo : Page
{
// 仿 toast 的 Popup
private Popup _popupToast = new Popup();
public PopupDemo()
{
this.InitializeComponent();
popup.Opened += delegate { lblMsg.Text = "popup.Opened"; };
popup.Closed += delegate { lblMsg.Text = "popup.Closed"; };
}
private void btnOpenPopup_Click(object sender, RoutedEventArgs e)
{
if (!popup.IsOpen)
popup.IsOpen = true;
}
private void btnClosePopup_Click(object sender, RoutedEventArgs e)
{
if (popup.IsOpen)
popup.IsOpen = false;
}
private void btnOpenPopupToast_Click(object sender, RoutedEventArgs e)
{
if (!_popupToast.IsOpen)
{
// 设置 Popup 中的内容
Border border = new Border();
border.BorderBrush = new SolidColorBrush(Colors.Red);
border.BorderThickness = new Thickness(1);
border.Background = new SolidColorBrush(Colors.Blue);
border.Width = 600;
border.Height = 100;
border.Child = new TextBlock() { Text = "我是 Popup", HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center };
// 设置 Popup 的相关属性
_popupToast.IsLightDismissEnabled = true;
_popupToast.Child = border;
_popupToast.VerticalOffset = 100d; // 设置 Popup 的显示位置(Popup 的默认显示位置在窗口 0,0 点)
_popupToast.ChildTransitions = new TransitionCollection() { new PaneThemeTransition() { Edge = EdgeTransitionLocation.Left } };
_popupToast.IsOpen = true;
}
}
}
}
3、PopupMenu 的示例
Controls/FlyoutControl/PopupMenuDemo.xamlPage
x:Class="Windows10.Controls.FlyoutControl.PopupMenuDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.Controls.FlyoutControl"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
Grid Background="Transparent">
StackPanel Margin="10 0 10 10">
TextBlock Name="lblMsg" Margin="5" />
TextBlock Name="lblDemo" Margin="5">
鼠标右键我或触摸 press-and-hold 我,以弹出 PopupMenu
TextBlock>
StackPanel>
Grid>
Page>
/*
* PopupMenu - 上下文菜单(未继承任何类)
* Commands - 上下文菜单中的命令集合,返回 IList
[源码下载]
上一篇:背水一战 Windows 10 (27) - 控件(文本类): TextBlock
下一篇:背水一战 Windows 10 (39) - 控件(布局类): VariableSizedWrapGrid, Border, Viewbox, SplitView
文章标题:背水一战 Windows 10 (36) - 控件(弹出类): ToolTip, Popup, PopupMenu
文章链接:http://soscw.com/essay/84875.html