Windows 8.1 新增控件之 Flyout

简介: 原文:Windows 8.1 新增控件之 Flyout本篇为大家介绍Flyout 控件,Flyout 属于一种轻量级交互控件,可以支持信息提示或用户交互。与传统Dialog 控件不同的是Flyout 控件可通过直接点击对话框外部区域忽略。
原文: Windows 8.1 新增控件之 Flyout

本篇为大家介绍Flyout 控件,Flyout 属于一种轻量级交互控件,可以支持信息提示或用户交互。与传统Dialog 控件不同的是Flyout 控件可通过直接点击对话框外部区域忽略。

Flyout 控件一般常与Button 结合使用,所以Button 控件默认增加了Flyout 属性,当使用Flyout 属性后,点击Button 时就会自动显示Flyout 内容,如下代码所示:

<Button Content="Delete Files">
    <Button.Flyout>
        <Flyout>
            <StackPanel>
                <TextBlock FontSize="15" Text="All the files will be deteled, Are you sure?" />
                <Button Content="Yes, delete all!"/>
            </StackPanel>
        </Flyout>
    </Button.Flyout>
</Button>

在Flyout 中仍然可以按需要添加各种控件,例如TextBlock、Button等。运行点击“Delete Files”按钮后,Flyout 内容将自动显示,如下图:

image

对于非Button 控件如何使用Flyout 呢,可以利用FlyoutBase.AttachedFlyout 属性为FrameworkElement 对象添加Flyout 功能,当然需要为该控件增加相应的触发事件来启动Flyout 功能。如下代码:

<TextBox Width="500" HorizontalAlignment="Left" GotFocus="TextBox_GotFocus">
    <FlyoutBase.AttachedFlyout>
        <Flyout>
            <TextBlock Text="You can input 50 words here."/>
        </Flyout>
    </FlyoutBase.AttachedFlyout>
</TextBox>
private void TextBox_GotFocus(object sender, RoutedEventArgs e)
{
    FrameworkElement element = sender as FrameworkElement;
    if (element != null)
    {
        FlyoutBase.ShowAttachedFlyout(element);
    }
}

运行效果如下图:

image

除此之外,也可以将Flyout 定义为StaticResource 供多种控件共享使用。

<Page.Resources>
    <Flyout x:Key="FlyoutResources">
        <StackPanel>
            <TextBlock Text="This is a Flyout."/>
        </StackPanel>
    </Flyout>
</Page.Resources>

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <StackPanel Margin="50" Orientation="Horizontal" VerticalAlignment="Top">
        <Button Content="Click Button" Flyout="{StaticResource FlyoutResources}"/>
        <TextBox FlyoutBase.AttachedFlyout="{StaticResource FlyoutResources}" Margin="50,20"
                 Height="20" Width="150" HorizontalAlignment="Left" GotFocus="TextBox_GotFocus"/>
    </StackPanel>
</Grid>

image

image

目录
相关文章
|
4月前
|
JavaScript Linux C#
【傻瓜级JS-DLL-WINCC-PLC交互】1.C#用windows窗体控件创建.net控件
【傻瓜级JS-DLL-WINCC-PLC交互】1.C#用windows窗体控件创建.net控件
65 0
|
11月前
|
C++ Windows
C++ Windows窗口程序:子窗口控件之按钮类button
C++ Windows窗口程序:子窗口控件之按钮类button
556 0
|
API C# Windows
C#实现操作Windows窗口句柄:遍历、查找窗体和控件【窗口句柄最全总结之一】
C#对Windows窗口或窗口句柄的操作,都是通过 P/Invoke Win32 API 实现的,DllImport引入Windows API操作窗口(句柄),可以实现枚举已打开的窗口、向窗口...
2077 0
C#实现操作Windows窗口句柄:遍历、查找窗体和控件【窗口句柄最全总结之一】
|
Windows
Windows程序设计——Windows单选按钮、复选框、分组框控件
Windows程序设计——Windows单选按钮、复选框、分组框控件
525 0
Windows程序设计——Windows单选按钮、复选框、分组框控件
|
Windows
Windows程序设计——(源代码)Windows单选按钮、复选框、分组框控件
Windows程序设计——(源代码)Windows单选按钮、复选框、分组框控件
166 0
windows窗口中控件的样式
windows窗口中控件的样式一.按钮样式 button BS_AUTO3STATE 创建一个与三态复选框相同的按钮,但该框在用户选择时更改其状态。状态循环通过检查,不确定和清除。 BS_AUTOCHECKBOX 创建一个与复选框相同的按钮,但每次用户选中复选框时,检查状态会自动在已选中和已清除之间切换。
1288 0
|
C# Windows 开发工具
WindowsXamlHost:在 WPF 中使用 UWP 的控件(Windows Community Toolkit)
原文 WindowsXamlHost:在 WPF 中使用 UWP 的控件(Windows Community Toolkit) Windows Community Toolkit 再次更新到 5.0。
1909 0
|
API Windows 开发工具
使用 Microsoft.UI.Xaml 解决 UWP 控件和对老版本 Windows 10 的兼容性问题
原文 使用 Microsoft.UI.Xaml 解决 UWP 控件和对老版本 Windows 10 的兼容性问题 虽然微软宣称 Windows 10 将是最后一个 Windows 版本,但由于年代跨越实在太久远,兼容性依然是避不开的问题。
1851 0
|
定位技术 Android开发 iOS开发
背水一战 Windows 10 (66) - 控件(WebView): 监听和处理 WebView 的事件
原文:背水一战 Windows 10 (66) - 控件(WebView): 监听和处理 WebView 的事件 [源码下载] 背水一战 Windows 10 (66) - 控件(WebView): 监听和处理 WebView 的事件 作者:webabcd介绍背水一战 Windows 10 之 ...
1298 0