[源码下载]

重新想象 Windows 8.1 Store Apps (74) - 新增控件: Flyout, MenuFlyout, SettingsFlyout

作者:webabcd

介绍
重新想象 Windows 8.1 Store Apps 之新增控件

  • Flyout - Flyout 控件
  • MenuFlyout - 菜单 Flyout 控件
  • SettingsFlyout - 设置面板 Flyout 控件

示例
1、演示 Flyout 的应用
FlyoutDemo.xaml

<Page
x:Class="Windows81.Controls.FlyoutDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows81.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"> <Page.Resources> <!--
通过资源的方式定义 flyout 的样式和内容
-->
<Flyout x:Key="SharedFlyout" Placement="Right">
<StackPanel>
<TextBlock Text="我是 Flyout 中的内容" Foreground="White" FontSize="24" />
</StackPanel>
<!--
FlyoutPresenterStyle - 用于定义 flyout 的显示样式
-->
<Flyout.FlyoutPresenterStyle>
<Style TargetType="FlyoutPresenter">
<Setter Property="ScrollViewer.ZoomMode" Value="Enabled"/>
<Setter Property="Background" Value="Blue"/>
<Setter Property="BorderBrush" Value="Red"/>
<Setter Property="BorderThickness" Value="10"/>
<Setter Property="MinHeight" Value="300"/>
<Setter Property="MinWidth" Value="300"/>
</Style>
</Flyout.FlyoutPresenterStyle>
</Flyout> </Page.Resources> <Grid Background="Transparent">
<StackPanel Margin="120 0 0 0"> <TextBlock Name="lblMsg" FontSize="14.667" /> <!--
Button 控件增加了一个 Flyout 属性(单击按钮后可以显示指定的 flyout)
-->
<Button Name="btnDemo" Content="按我弹出 Flyout" Margin="0 20 0 0">
<Button.Flyout>
<!--
Flyout - flyout 控件
Placement - flyout 的显示位置(FlyoutPlacementMode 枚举:Top, Bottom, Left, Right, Full - 屏幕中央)
Opening - flyout 准备显示时触发的事件
Opened - flyout 显示之后触发的事件
Closed - flyout 隐藏之后触发的事件
-->
<Flyout Placement="Right" Opening="Flyout_Opening" Opened="Flyout_Opened" Closed="Flyout_Closed">
<StackPanel>
<TextBlock>我是 Flyout 中的内容</TextBlock>
<Button Click="Button_Click">隐藏 Flyout</Button>
</StackPanel>
</Flyout>
</Button.Flyout>
</Button> <!--
让 FrameworkElement 弹出 flyout(通过 FlyoutBase.AttachedFlyout 来定义 FrameworkElement 对应的 flyout)
不会自动弹出,需要后台代码处理
-->
<TextBlock Text="按我弹出 Flyout" Margin="0 20 0 0" Tapped="TextBlock_Tapped" FontSize="18">
<FlyoutBase.AttachedFlyout>
<Flyout>
<TextBlock Text="我是 Flyout 中的内容" />
</Flyout>
</FlyoutBase.AttachedFlyout>
</TextBlock> <!--
通过指定资源的方式,设置 flyout 的样式和内容
-->
<TextBlock Text="按我弹出 Flyout" Margin="0 20 0 0" Tapped="TextBlock_Tapped" FontSize="18"
FlyoutBase.AttachedFlyout="{StaticResource SharedFlyout}" /> </StackPanel>
</Grid>
</Page>

FlyoutDemo.xaml.cs

/*
* Flyout - Flyout 控件(点击 Flyout 外部的话,Flyout 会自动关闭),继承自 FlyoutBase
*/ using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Input; namespace Windows81.Controls
{
public sealed partial class FlyoutDemo : Page
{
public FlyoutDemo()
{
this.InitializeComponent();
} private void Button_Click(object sender, RoutedEventArgs e)
{
// Flyout 继承自 FlyoutBase
FlyoutBase flyout = btnDemo.Flyout; // FlyoutBase.Hide() - 隐藏 Flyout
flyout.Hide();
} private void TextBlock_Tapped(object sender, TappedRoutedEventArgs e)
{
FrameworkElement element = sender as FrameworkElement; // FlyoutBase.ShowAttachedFlyout(FrameworkElement flyoutOwner) - 在指定的 FrameworkElement 上显示 flyout
FlyoutBase.ShowAttachedFlyout(element); // FlyoutBase.GetAttachedFlyout(FrameworkElement element) - 获取指定 FrameworkElement 上定义的 flyout
FlyoutBase flyout = FlyoutBase.GetAttachedFlyout(element); // FlyoutBase.ShowAt(FrameworkElement placementTarget) - 在指定的 FrameworkElement 上显示指定的 flyout
// flyout.ShowAt(btnDemo);
} private void Flyout_Opening(object sender, object e)
{
lblMsg.Text = "Flyout 打开中";
} private void Flyout_Opened(object sender, object e)
{
lblMsg.Text = "Flyout 已打开";
} private void Flyout_Closed(object sender, object e)
{
lblMsg.Text = "Flyout 已关闭";
}
}
}

2、演示 MenuFlyout 的应用
MenuFlyoutDemo.xaml

<Page
x:Class="Windows81.Controls.MenuFlyoutDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows81.Controls"
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="120 0 0 0"> <TextBlock Name="lblMsg" FontSize="14.667" /> <Button Content="Options" Margin="0 20 0 0">
<Button.Flyout>
<!--
MenuFlyout - MenuFlyout 控件
Items - MenuFlyout 中包含的 item(MenuFlyoutItem, ToggleMenuFlyoutItem, MenuFlyoutSeparator)
-->
<MenuFlyout> <!--
MenuFlyoutItem - MenuFlyout 中的 item
ToggleMenuFlyoutItem - MenuFlyout 中的可以 toggle 的 item
MenuFlyoutSeparator - MenuFlyout 中的分隔符
--> <MenuFlyoutItem Text="MenuFlyoutItem" Click="MenuFlyoutItem_Click" />
<MenuFlyoutSeparator/>
<ToggleMenuFlyoutItem Text="ToggleMenuFlyoutItem1" IsChecked="True" />
<ToggleMenuFlyoutItem Text="ToggleMenuFlyoutItem2" IsChecked="True" />
<!--
MenuFlyout.MenuFlyoutPresenterStyle - 用于定义 MenuFlyout 的显示样式
-->
<MenuFlyout.MenuFlyoutPresenterStyle>
<Style TargetType="MenuFlyoutPresenter">
<Setter Property="BorderBrush" Value="Red"/>
<Setter Property="BorderThickness" Value="5"/>
</Style>
</MenuFlyout.MenuFlyoutPresenterStyle>
</MenuFlyout>
</Button.Flyout>
</Button> </StackPanel>
</Grid>
</Page>

MenuFlyoutDemo.xaml.cs

/*
* MenuFlyout - 菜单 Flyout 控件(点击 Flyout 外部的话,Flyout 会自动关闭),继承自 FlyoutBase
*/ using Windows.UI.Xaml.Controls; namespace Windows81.Controls
{
public sealed partial class MenuFlyoutDemo : Page
{
public MenuFlyoutDemo()
{
this.InitializeComponent();
} private void MenuFlyoutItem_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
lblMsg.Text = "MenuFlyoutItem 被 click 了";
}
}
}

3、演示 SettingsFlyout 的应用
SettingsFlyout/SettingsFlyout1.xaml

<SettingsFlyout
x:Class="Windows81.Controls.SettingsFlyout.SettingsFlyout1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows81.Controls.SettingsFlyout"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" Title="SettingsFlyout 1"
IconSource="/Assets/SmallLogo.png"
HeaderForeground="White"
HeaderBackground="#00b2f0"
Background="White"> <!--
SettingsFlyout - 设置面板(本例是通过 SettingsFlyout 模板创建的)
Title - 标题
IconSource - 图标(在标题右侧)
HeaderForeground - header 的前景色
HeaderBackground - header 的背景色
Background - 设置面板的背景
--> <!-- 此 StackPanel 充当内容部分的垂直布局的根面板-->
<StackPanel VerticalAlignment="Stretch" HorizontalAlignment="Stretch" > <!-- 下列 StackPanel 定义个别内容部分--> <!-- 第 1 部分内容-->
<StackPanel Style="{StaticResource SettingsFlyoutSectionStyle}"> <!-- 第 1 部分标题-->
<TextBlock Style="{StaticResource TitleTextBlockStyle}" Text="Lorem ipsum" /> <!-- 第 1 部分正文-->
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Margin="0,0,0,25" TextWrapping="Wrap">
<TextBlock.Text>
Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
</TextBlock.Text>
</TextBlock> </StackPanel> <!-- 根据需要在下面定义更多内容部分--> </StackPanel>
</SettingsFlyout>

SettingsFlyout/Demo.xaml

<Page
x:Class="Windows81.Controls.SettingsFlyout.Demo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows81.Controls.SettingsFlyout"
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="120 0 0 0"> <Button Name="btnShowSettingsFlyout" Content="显示通过 SettingsFlyout 实现的自定义设置面板 " Click="btnShowSettingsFlyout_Click" /> </StackPanel>
</Grid>
</Page>

SettingsFlyout/Demo.xaml.cs

/*
* SettingsFlyout - 设置面板 Flyout 控件
*
* 本例用于演示如何弹出 SettingsFlyout,实际的 SettingsFlyout 页面请参见:SettingsFlyout1.xaml
*/ using Windows.UI.ApplicationSettings;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation; namespace Windows81.Controls.SettingsFlyout
{
public sealed partial class Demo : Page
{
public Demo()
{
this.InitializeComponent();
} protected override void OnNavigatedTo(NavigationEventArgs e)
{
SettingsPane.GetForCurrentView().CommandsRequested += onCommandsRequested;
} protected override void OnNavigatedFrom(NavigationEventArgs e)
{
SettingsPane.GetForCurrentView().CommandsRequested -= onCommandsRequested; base.OnNavigatedFrom(e);
} void onCommandsRequested(SettingsPane settingsPane, SettingsPaneCommandsRequestedEventArgs e)
{
// 关联到 charm 栏的设置按钮
SettingsCommand myCommand = new SettingsCommand("myCommand", "SettingsFlyout 面板",
(handler) =>
{
SettingsFlyout1 sf = new SettingsFlyout1(); // SettingsFlyout.Show() - 显示指定的 SettingsFlyout(Show - 通过 charm 栏的设置按钮弹出;ShowIndependent - 通过自己写代码的方式弹出)
sf.Show(); // SettingsFlyout.Hide() - 隐藏指定的 SettingsFlyout
// sf.Hide();
});
e.Request.ApplicationCommands.Add(myCommand);
} private void btnShowSettingsFlyout_Click(object sender, RoutedEventArgs e)
{
SettingsFlyout1 sf = new SettingsFlyout1(); // 点击了 SettingsFlyout 的后退按钮时触发的事件
// sf.BackClick += xxx; // SettingsFlyout.ShowIndependent() - 显示指定的 SettingsFlyout(ShowIndependent - 通过自己写代码的方式弹出;Show - 通过 charm 栏的设置按钮弹出)
sf.ShowIndependent(); // SettingsFlyout.Hide() - 隐藏指定的 SettingsFlyout
// sf.Hide();
}
}
}

OK
[源码下载]

重新想象 Windows 8.1 Store Apps (74) - 新增控件: Flyout, MenuFlyout, SettingsFlyout的更多相关文章

  1. 重新想象 Windows 8.1 Store Apps (72) - 新增控件: AppBar, CommandBar

    [源码下载] 重新想象 Windows 8.1 Store Apps (72) - 新增控件: AppBar, CommandBar 作者:webabcd 介绍重新想象 Windows 8.1 Sto ...

  2. 重新想象 Windows 8.1 Store Apps (73) - 新增控件: DatePicker, TimePicker

    [源码下载] 重新想象 Windows 8.1 Store Apps (73) - 新增控件: DatePicker, TimePicker 作者:webabcd 介绍重新想象 Windows 8.1 ...

  3. 重新想象 Windows 8.1 Store Apps (75) - 新增控件: Hub, Hyperlink

    [源码下载] 重新想象 Windows 8.1 Store Apps (75) - 新增控件: Hub, Hyperlink 作者:webabcd 介绍重新想象 Windows 8.1 Store A ...

  4. 重新想象 Windows 8.1 Store Apps (76) - 新增控件: SearchBox

    [源码下载] 重新想象 Windows 8.1 Store Apps (76) - 新增控件: SearchBox 作者:webabcd 介绍重新想象 Windows 8.1 Store Apps 之 ...

  5. 重新想象 Windows 8.1 Store Apps 系列文章索引

    [源码下载] [重新想象 Windows 8 Store Apps 系列文章] 重新想象 Windows 8.1 Store Apps 系列文章索引 作者:webabcd 1.重新想象 Windows ...

  6. 重新想象 Windows 8.1 Store Apps (81) - 控件增强: WebView 之加载本地 html, 智能替换 html 中的 url 引用, 通过 Share Contract 分享 WebView 中的内容, 为 WebView 截图

    [源码下载] 重新想象 Windows 8.1 Store Apps (81) - 控件增强: WebView 之加载本地 html, 智能替换 html 中的 url 引用, 通过 Share Co ...

  7. 重新想象 Windows 8.1 Store Apps (77) - 控件增强: 文本类控件的增强, 部分控件增加了 Header 属性和 HeaderTemplate 属性, 部分控件增加了 PlaceholderText 属性

    [源码下载] 重新想象 Windows 8.1 Store Apps (77) - 控件增强: 文本类控件的增强, 部分控件增加了 Header 属性和 HeaderTemplate 属性, 部分控件 ...

  8. 重新想象 Windows 8.1 Store Apps (78) - 控件增强: ScrollViewer, FlipView, Popup

    [源码下载] 重新想象 Windows 8.1 Store Apps (78) - 控件增强: ScrollViewer, FlipView, Popup 作者:webabcd 介绍重新想象 Wind ...

  9. 重新想象 Windows 8.1 Store Apps (79) - 控件增强: MediaElement, Frame

    [源码下载] 重新想象 Windows 8.1 Store Apps (79) - 控件增强: MediaElement, Frame 作者:webabcd 介绍重新想象 Windows 8.1 St ...

随机推荐

  1. UnionPay,ChinaPay 最新 银联支付接口C#\Asp.net\MVC 版本

    1.概念普及 一.理解什么是UnionPay.ChinaPay 这两个概念如果搞不清楚,绝对够你瞎折腾一段时间的. UnionPay:中国银联,最大的机构:他本身也提供系统接口但都是B2B的,对于单个 ...

  2. Turn off swi-prolog protocol output of ANSI terminal control sequences

    To save a record of program execution in prolog, we use the special predicates: protocol and noproto ...

  3. apache工作模式:prefork和worker

    apache作为现今web服务器用的最广泛也是最稳定的开源服务器软件,其工作模式有许多中,目前主要有两种模式:prefork模式和worker模式 一.两种模式 prefork模式: prefork是 ...

  4. [GraphQL] Use GraphQL's List Type for Collections

    In order to handle collections of items in a GraphQL Schema, GraphQL has a List Type. In this video, ...

  5. WinForm 批量设置指定控件中的控件状态

    在开发中常遇到当点击某个按钮的时候,禁用文本框或按钮的的状态,以防止误操作,下面的代码是我已批量设置指定控件中的按钮状态的代码,同理可以延伸出很多操作. /// <summary> /// ...

  6. PHP vs Python

    最近在搞微信公众号方面的开发,发现很多开发微信公众号都使用PHP来开发,由于我之前开发Web端喜欢使用Python,所以从Quora网站找出一篇Which-is-better-PHP-or-Pytho ...

  7. 牢骚与javascript中的this

    最近在看关于拖延症的一本书<拖拉一点也无妨>,后面得出结论是自己写博客大部分处于两种状态,心情很好和心情很不好的时候.因为正常状态下感觉写博客吧,是件很麻烦的事情,不如去看看电影看看漫画啥 ...

  8. Git 执行 「fork 出来的仓库」和「最新版本的原仓库」内容同步更新

    当我们在 GitHub 上 fork 出一个仓库后,如果原仓库更新了,此时怎样才能保证我们 fork 出来的仓库和原仓库内容一致呢?我们一般关注的是仓库的 master(主干分支)的内容,通过以下步骤 ...

  9. C++ Low level performance optimize

    C++ Low level performance optimize 1.  May I have 1 bit ? 下面两段代码,哪一个占用空间更少,那个速度更快?思考10秒再继续往下看:) //v1 ...

  10. 实现让Lync client也能够"潜水"隐身聊天

    看到MSN或QQ,都支持隐身聊天. Lync Server  2013也是支持的.   1.Server端:Lync 2013 Server 缺省策略是没有设置显示脱机功能.(设置前截图)   2.直 ...