示例
1、ToolTip 的示例
Controls/FlyoutControl/ToolTipDemo.xaml

  1. <Page
  2. x:Class="Windows10.Controls.FlyoutControl.ToolTipDemo"
  3. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  4. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  5. xmlns:local="using:Windows10.Controls.FlyoutControl"
  6. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  7. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  8. mc:Ignorable="d">
  9.  
  10. <Grid Background="Transparent">
  11. <StackPanel Margin="10 0 10 10">
  12.  
  13. <!--
  14. ToolTip - 提示框控件
  15. Content - 提示内容
  16. Placement - 提示框的显示位置(Bottom, Right, Mouse, Left, Top)
  17. HorizontalOffset - 水平偏移量
  18. VerticalOffset - 垂直偏移量
  19. IsOpen - 提示框是否是显示状态(如果要设置此属性的话,需要等到宿主加载完之后再设置)
  20. Closed - 提示框关闭后触发的事件
  21. Opened - 提示框打开后触发的事件
  22. -->
  23.  
  24. <TextBlock Name="textBlock1" Text="TextBlock" Margin="5"
  25. ToolTipService.ToolTip="ToolTip 的内容"
  26. ToolTipService.Placement="Right" />
  27.  
  28. <TextBlock Name="textBlock2" Text="TextBlock" Margin="5">
  29. <ToolTipService.ToolTip>
  30. <ToolTip Content="ToolTip 的内容" Placement="Mouse"
  31. HorizontalOffset="120" VerticalOffset="0"
  32. Opened="toolTip_Opened" Closed="toolTip_Closed" />
  33. </ToolTipService.ToolTip>
  34. </TextBlock>
  35. <TextBlock Name="lblMsg" Margin="5" />
  36.  
  37. </StackPanel>
  38. </Grid>
  39. </Page>

Controls/FlyoutControl/ToolTipDemo.xaml.cs

  1. /*
  2. * ToolTip - 提示框控件(继承自 ContentControl, 请参见 /Controls/BaseControl/ContentControlDemo/)
  3. */
  4.  
  5. using Windows.UI.Xaml;
  6. using Windows.UI.Xaml.Controls;
  7.  
  8. namespace Windows10.Controls.FlyoutControl
  9. {
  10. public sealed partial class ToolTipDemo : Page
  11. {
  12. public ToolTipDemo()
  13. {
  14. this.InitializeComponent();
  15. }
  16.  
  17. private void toolTip_Opened(object sender, RoutedEventArgs e)
  18. {
  19. lblMsg.Text = "textBlock2 toolTip_Opened";
  20. }
  21.  
  22. private void toolTip_Closed(object sender, RoutedEventArgs e)
  23. {
  24. lblMsg.Text = "textBlock2 toolTip_Closed";
  25. }
  26. }
  27. }

2、Popup 的示例
Controls/FlyoutControl/PopupDemo.xaml

  1. <Page
  2. x:Class="Windows10.Controls.FlyoutControl.PopupDemo"
  3. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  4. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  5. xmlns:local="using:Windows10.Controls.FlyoutControl"
  6. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  7. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  8. mc:Ignorable="d">
  9.  
  10. <Grid Background="Transparent">
  11. <StackPanel Margin="10 0 10 10">
  12.  
  13. <!--
  14. Popup - 弹出框控件
  15. Child - 弹出框的内容([ContentProperty(Name = "Child")]),一个 UIElement 类型的对象
  16. ChildTransitions - 显示弹出框时,其内容的过渡效果
  17. IsLightDismissEnabled - 点击非 Popup 区域时否关闭 Popup
  18. HorizontalOffset - 水平方向上的偏移量
  19. VerticalOffset - 垂直方向上的偏移量
  20. -->
  21. <Popup Name="popup" Margin="5"
  22. HorizontalOffset="200" VerticalOffset="10" IsLightDismissEnabled="{Binding IsChecked, ElementName=chkIsLightDismissEnabled}">
  23. <Border BorderBrush="Red" BorderThickness="1" Background="Orange" Width="200" Height="200">
  24. <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
  25. <TextBlock Text="我是 Popup" HorizontalAlignment="Center" />
  26. <Button Name="btnClosePopup" Content="关闭" HorizontalAlignment="Center" Click="btnClosePopup_Click" />
  27. </StackPanel>
  28. </Border>
  29. <!--为弹出框增加 PopupThemeTransition 效果-->
  30. <Popup.ChildTransitions>
  31. <TransitionCollection>
  32. <PopupThemeTransition />
  33. </TransitionCollection>
  34. </Popup.ChildTransitions>
  35. </Popup>
  36. <TextBlock Name="lblMsg" Margin="5" />
  37.  
  38. <!--
  39. 显示 xaml 方式定义的 popup
  40. -->
  41. <StackPanel Orientation="Horizontal" Margin="5">
  42. <Button Name="btnOpenPopup" Content="弹出 Popup" Click="btnOpenPopup_Click" />
  43. <CheckBox Name="chkIsLightDismissEnabled" IsChecked="False" Content="IsLightDismissEnabled" Margin="10 0 0 0" />
  44. </StackPanel>
  45.  
  46. <!--
  47. 显示 code-behind 方式定义的 popup
  48. -->
  49. <Button Name="btnOpenPopupToast" Content="弹出仿 toast 的 Popup" Click="btnOpenPopupToast_Click" Margin="5" />
  50.  
  51. </StackPanel>
  52. </Grid>
  53. </Page>

Controls/FlyoutControl/PopupDemo.xaml.cs

  1. /*
  2. * Popup - 弹出框控件(继承自 FrameworkElement, 请参见 /Controls/BaseControl/FrameworkElementDemo.xaml)
  3. * IsOpen - 弹出框是否是打开的状态(如果要设置此属性,需要在控件加载之后)
  4. * Opened - 弹出框打开后触发的事件
  5. * Closed - 弹出框关闭后触发的事件
  6. */
  7.  
  8. using Windows.UI;
  9. using Windows.UI.Xaml;
  10. using Windows.UI.Xaml.Controls;
  11. using Windows.UI.Xaml.Controls.Primitives;
  12. using Windows.UI.Xaml.Media;
  13. using Windows.UI.Xaml.Media.Animation;
  14.  
  15. namespace Windows10.Controls.FlyoutControl
  16. {
  17. public sealed partial class PopupDemo : Page
  18. {
  19. // 仿 toast 的 Popup
  20. private Popup _popupToast = new Popup();
  21.  
  22. public PopupDemo()
  23. {
  24. this.InitializeComponent();
  25.  
  26. popup.Opened += delegate { lblMsg.Text = "popup.Opened"; };
  27. popup.Closed += delegate { lblMsg.Text = "popup.Closed"; };
  28. }
  29.  
  30. private void btnOpenPopup_Click(object sender, RoutedEventArgs e)
  31. {
  32. if (!popup.IsOpen)
  33. popup.IsOpen = true;
  34. }
  35.  
  36. private void btnClosePopup_Click(object sender, RoutedEventArgs e)
  37. {
  38. if (popup.IsOpen)
  39. popup.IsOpen = false;
  40. }
  41.  
  42. private void btnOpenPopupToast_Click(object sender, RoutedEventArgs e)
  43. {
  44. if (!_popupToast.IsOpen)
  45. {
  46. // 设置 Popup 中的内容
  47. Border border = new Border();
  48. border.BorderBrush = new SolidColorBrush(Colors.Red);
  49. border.BorderThickness = new Thickness(1);
  50. border.Background = new SolidColorBrush(Colors.Blue);
  51. border.Width = 600;
  52. border.Height = 100;
  53. border.Child = new TextBlock() { Text = "我是 Popup", HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center };
  54.  
  55. // 设置 Popup 的相关属性
  56. _popupToast.IsLightDismissEnabled = true;
  57. _popupToast.Child = border;
  58. _popupToast.VerticalOffset = 100d; // 设置 Popup 的显示位置(Popup 的默认显示位置在窗口 0,0 点)
  59. _popupToast.ChildTransitions = new TransitionCollection() { new PaneThemeTransition() { Edge = EdgeTransitionLocation.Left } };
  60.  
  61. _popupToast.IsOpen = true;
  62. }
  63. }
  64. }
  65. }

3、PopupMenu 的示例
Controls/FlyoutControl/PopupMenuDemo.xaml

  1. <Page
  2. x:Class="Windows10.Controls.FlyoutControl.PopupMenuDemo"
  3. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  4. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  5. xmlns:local="using:Windows10.Controls.FlyoutControl"
  6. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  7. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  8. mc:Ignorable="d">
  9.  
  10. <Grid Background="Transparent">
  11. <StackPanel Margin="10 0 10 10">
  12.  
  13. <TextBlock Name="lblMsg" Margin="5" />
  14.  
  15. <TextBlock Name="lblDemo" Margin="5">
  16. 鼠标右键我或触摸 press-and-hold 我,以弹出 PopupMenu
  17. </TextBlock>
  18.  
  19. </StackPanel>
  20. </Grid>
  21. </Page>

Controls/FlyoutControl/PopupMenuDemo.xaml.cs

  1. /*
  2. * PopupMenu - 上下文菜单(未继承任何类)
  3. * Commands - 上下文菜单中的命令集合,返回 IList<IUICommand> 类型的数据
  4. * IAsyncOperation<IUICommand> ShowAsync(Point invocationPoint) - 在指定的位置(PopupMenu 的默认显示位置在窗口 0,0 点)上显示上下文菜单,并返回用户激发的命令
  5. * IAsyncOperation<IUICommand> ShowForSelectionAsync(Rect selection, Placement preferredPlacement) - 在指定的矩形区域的指定方位显示上下文菜单,并返回用户激发的命令
  6. *
  7. * IUICommand - 命令
  8. * Label - 显示的文字
  9. * Id - 参数
  10. *
  11. * UICommandSeparator - 分隔符
  12. */
  13.  
  14. using System;
  15. using Windows.UI.Popups;
  16. using Windows.UI.Xaml;
  17. using Windows.UI.Xaml.Controls;
  18. using Windows.UI.Xaml.Input;
  19. using Windows10.Common;
  20.  
  21. namespace Windows10.Controls.FlyoutControl
  22. {
  23. public sealed partial class PopupMenuDemo : Page
  24. {
  25. public PopupMenuDemo()
  26. {
  27. this.InitializeComponent();
  28.  
  29. lblDemo.RightTapped += lblDemo_RightTapped;//右键单击
            this.Tapped += PopupMenuDemo_Tapped;//左键点击
  30. }

      private async void PopupMenuDemo_Tapped(object sender, TappedRoutedEventArgs e)
          {
            var msgDialog = new  MessageDialog("我是一个提示内容") { Title = "提示标题" };
            msgDialog.Commands.Add(new UICommand("确定", uiCommand => { tb.Text = $"您点击了:{uiCommand.Label}"; }));
            msgDialog.Commands.Add(new UICommand("取消", uiCommand => { tb.Text = $"您点击了:{uiCommand.Label}"; }));
            await msgDialog.ShowAsync();

}

  1. private async void lblDemo_RightTapped(object sender, RightTappedRoutedEventArgs e)
  2. {
  3. PopupMenu menu = new PopupMenu();
  4.  
  5. menu.Commands.Add
  6. (
  7. new UICommand
  8. (
  9. "item1",
  10. (command) =>
  11. {
  12. lblMsg.Text = string.Format("command label:{0}, id:{1}", command.Label, command.Id);
  13. },
  14. "param1"
  15. )
  16. );
  17.  
  18. menu.Commands.Add
  19. (
  20. new UICommand
  21. (
  22. "item2",
  23. (command) =>
  24. {
  25. lblMsg.Text = string.Format("command label:{0}, id:{1}", command.Label, command.Id);
  26. },
  27. "param2"
  28. )
  29. );
  30.  
  31. // 分隔符
  32. menu.Commands.Add(new UICommandSeparator());
  33.  
  34. menu.Commands.Add
  35. (
  36. new UICommand
  37. (
  38. "item3",
  39. (command) =>
  40. {
  41. lblMsg.Text = string.Format("command label:{0}, id:{1}", command.Label, command.Id);
  42. },
  43. "param3"
  44. )
  45. );
  46.  
  47. // 在指定的位置显示上下文菜单,并返回用户激发的命令(测试的时候这里有时会发生异常,不知道什么原因,所以还是尽量用 MenuFlyout 吧)
  48. IUICommand chosenCommand = await menu.ShowForSelectionAsync(Helper.GetElementRect((FrameworkElement)sender), Placement.Below);
  49. if (chosenCommand == null) // 用户没有在上下文菜单中激发任何命令
  50. {
  51. lblMsg.Text = "用户没有选择任何命令";
  52. }
  53. else
  54. {
  55. lblMsg.Text += Environment.NewLine;
  56. lblMsg.Text += string.Format("result label:{0}, id:{1}", chosenCommand.Label, chosenCommand.Id);
  57. }
  58. }
  59. }
  60. }

控件(弹出类): ToolTip, Popup, PopupMenu的更多相关文章

  1. 根据条件决定My97DatePicker日期控件弹出的日期格式

    代码如下: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <tit ...

  2. my97日期控件弹出位置显示异常

    使用my97日期选择控件的时候,如果整个页面是有滚动条的,根据触发显示日期的控件的父控件的position不同会显示不同的情况 1.position不为fixed则滑动滚动条,显示的日期层不会出现异常 ...

  3. 背水一战 Windows 10 (36) - 控件(弹出类): ToolTip, Popup, PopupMenu

    [源码下载] 背水一战 Windows 10 (36) - 控件(弹出类): ToolTip, Popup, PopupMenu 作者:webabcd 介绍背水一战 Windows 10 之 控件(弹 ...

  4. 背水一战 Windows 10 (37) - 控件(弹出类): MessageDialog, ContentDialog

    [源码下载] 背水一战 Windows 10 (37) - 控件(弹出类): MessageDialog, ContentDialog 作者:webabcd 介绍背水一战 Windows 10 之 控 ...

  5. 背水一战 Windows 10 (35) - 控件(弹出类): FlyoutBase, Flyout, MenuFlyout

    [源码下载] 背水一战 Windows 10 (35) - 控件(弹出类): FlyoutBase, Flyout, MenuFlyout 作者:webabcd 介绍背水一战 Windows 10 之 ...

  6. 背水一战 Windows 10 (32) - 控件(选择类): Selector, ComboBox

    [源码下载] 背水一战 Windows 10 (32) - 控件(选择类): Selector, ComboBox 作者:webabcd 介绍背水一战 Windows 10 之 控件(选择类) Sel ...

  7. 背水一战 Windows 10 (31) - 控件(按钮类): ButtonBase, Button, HyperlinkButton, RepeatButton, ToggleButton, AppBarButton, AppBarToggleButton

    [源码下载] 背水一战 Windows 10 (31) - 控件(按钮类): ButtonBase, Button, HyperlinkButton, RepeatButton, ToggleButt ...

  8. 控件(按钮类): ButtonBase, Button, HyperlinkButton, RepeatButton, ToggleButton, AppBarButton, AppBarToggleButton

    介绍背水一战 Windows 10 之 控件(按钮类) ButtonBase Button HyperlinkButton RepeatButton ToggleButton AppBarButton ...

  9. 【WPF】监听WPF的WebBrowser控件弹出新窗口的事件

    原文:[WPF]监听WPF的WebBrowser控件弹出新窗口的事件 WPF中自带一个WebBrowser控件,当我们使用它打开一个网页,例如百度,然后点击它其中的链接时,如果这个链接是会弹出一个新窗 ...

  10. 背水一战 Windows 10 (62) - 控件(媒体类): InkCanvas 保存和加载, 手写识别

    [源码下载] 背水一战 Windows 10 (62) - 控件(媒体类): InkCanvas 保存和加载, 手写识别 作者:webabcd 介绍背水一战 Windows 10 之 控件(媒体类) ...

随机推荐

  1. USB Type-C 接口有什么优点?

    USB Type-C 接口有什么优点? 提到USB Type-C接口(以下简称为USB-C),大家第一个能想到的是USB-C接口能正反插,用起来很舒服.了解更多的可能还支持USB-C接口速度更快, 达 ...

  2. [转]mvc3 使用session来存储类来存储用户登陆信息

    mvc3 使用session来存储类来存储用户登陆信息 2013-08-26 09:48:56|  分类: NET开发 |举报 |字号 订阅   项目之前的登陆机制是这样的:用户登陆后初始化一个类,类 ...

  3. maven-安装配置

    Maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具. maven是什么maven这个词可以翻译为“知识的积累”,也可以翻译为“专家”或“内行” ...

  4. [转] 如何设置Eclipse的上网代理

    from: http://blog.csdn.net/qq635785620/article/details/8191799 不同版本的eclipse有不同的设置方法 方式一:   默认的Eclips ...

  5. tyvj1098[luogu 2365]任务安排 batch

    题目描述 N个任务排成一个序列在一台机器上等待完成(顺序不得改变),这N个任务被分成若干批,每批包含相邻的若干任务.从时刻0开始,这些任务被分批加工,第i个任务单独完成所需的时间是Ti.在每批任务开始 ...

  6. noip2013 积木大赛

    题目描述 春春幼儿园举办了一年一度的“积木大赛”.今年比赛的内容是搭建一座宽度为n的大厦,大厦可以看成由n块宽度为1的积木组成,第i块积木的最终高度需要是hi. 在搭建开始之前,没有任何积木(可以看成 ...

  7. 在VisualStudio2013,2015中如何安装自定义项目模板

    For example, I want to install EP prj template: AxWebProject.zip Copy AxWebProject.zip zip file into ...

  8. eclipse服务器add and remove 工程时出现there are no resources that can be added or removed from the server

    网上的解决方法: 解决方法: 第1步.新建一个“Dynamic Web Project” 第2步.把新建项目里面的.project文件和.settings文件夹复制到导入的那个项目里面. 可是我发现: ...

  9. win7 IIS7.5配置伪静态

    转自:http://www.cnblogs.com/luckly-hf/archive/2013/03/07/2947687.html 第一部: 从如下地址中下载URLRewriter组件组件: 官方 ...

  10. 转:用WCAT进行IIS压力测试

    Microsoft的Web容量分析工具(WCAT) 是测试你的客户-服务器网络配置的必备工具.这个工具在你的网络上对多种工作量的场景进行仿真,允许你确定你的网络和服务器的最佳配置.WCAT是专门为 评 ...