[源码下载]

重新想象 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. 1.什么是泛型和C#中泛型在Class上的实现

    阅读目录 一:什么是泛型? 二:C#中泛型在Class上的实现   一:什么是泛型? 我们在编程的时候需要一个数据类型,但是在刚开始的时候还不确定这个数据类型是怎么样的,或者说对于不同的多个数据类型有 ...

  2. 表格类似Excel

    只是很简单的实现表格,使用GridView控件-->可以上下左右滚动,但是不能合并 直接上代码: 1.主要布局 <?xml version="1.0" encoding ...

  3. 利用nodejs+phantomjs+casperjs采集淘宝商品的价格

    因为一些业务需求需要采集淘宝店铺商品的销售价格,但是淘宝详情页面的价格显示是通过js动态调用显示的.所以就没法通过普通的获取页面html然后通过正则或者xpath的方式获取到想到的信息了. 所幸我们现 ...

  4. Selenium WebDriver屏幕截图(C#版)

    Selenium WebDriver屏幕截图(C#版)http://www.automationqa.com/forum.php?mod=viewthread&tid=3595&fro ...

  5. maven eclipse jetty debug

    可以通过查看最近版本: http://mvnrepository.com/artifact/org.eclipse.jetty/jetty-server http://search.maven.org ...

  6. C# 类型基础——你可能忽略的技术细节

    引言 本文之初的目的是讲述设计模式中的 Prototype(原型)模式,但是如果想较清楚地弄明白这个模式,需要了解对象克隆(Object Clone),Clone 其实也就是对象复制.复制又分为了浅度 ...

  7. Android开发常见问题

    1. android模拟机上不能加文件提示read only file system 先:adb shell 后:mount -o remount ,rw /就行不需要附加多余的东西 就上面两行,解决 ...

  8. Clough-Tocher

    Clough-Tocher The Clough-Tocher interpolation technique is often referred to in the literature as a ...

  9. Asp.net Mvc4 使用Cas单点登录

    因项目需要,使用了耶鲁大学的Cas单点登录方案,在java中使用一直正常,但是在.Net中碰到了循环重定向的问题,反复测试后,总算解决了,最终的配置如下: <?xml version=" ...

  10. JS对象的几个方法介绍

    1.hasOwnProperty 判断是不是对象自身的属性,如果是继承的返回false否则true function Fn(){ } Fn.prototype.num = 10; var obj = ...