[UWP]使用Reveal

1. 前言

之前在 如何使用Fluent Design System 这篇文章里已经简单介绍过Reveal的用法,这篇再详细介绍其它内容。

2. 自定义RevealButtonStyle

我觉得常用ItemsControl都已经自动应用了Reveal,用就是了。

没有默认应用Reveal的控件,UWP也为其中一部分提供了可用的Reveal样式。

只需简单地应用Style即可:

<Button Content="Button Content" Style="{StaticResource ButtonRevealStyle}"/>

其它用法官方文档也有很详细的教程,一时也想不到能玩出什么花样。。

但既然Reveal最大的作用是为一组元素提示其可操作区域,那么对无边框按钮来说Reveal就很重要了。UWP没有提供无边框按钮的Reveal样式,可以自己实现一个:

<Style TargetType="Button">
    <Setter Property="Background"
            Value="{ThemeResource ButtonRevealBackground}" />
    <Setter Property="Foreground"
            Value="{ThemeResource ButtonForeground}" />
    <Setter Property="BorderBrush"
            Value="{ThemeResource ButtonRevealBorderBrush}" />
    <Setter Property="BorderThickness"
            Value="{ThemeResource ButtonRevealBorderThemeThickness}" />
    <Setter Property="Margin"
            Value="3" />
    <Setter Property="HorizontalAlignment"
            Value="Left" />
    <Setter Property="VerticalAlignment"
            Value="Center" />
    <Setter Property="FontFamily"
            Value="{ThemeResource ContentControlThemeFontFamily}" />
    <Setter Property="FontWeight"
            Value="Normal" />
    <Setter Property="FontSize"
            Value="20" />
    <Setter Property="UseSystemFocusVisuals"
            Value="True" />
    <Setter Property="FocusVisualMargin"
            Value="-3" />
    <Setter Property="Height"
            Value="50" />
    <Setter Property="Width"
            Value="50" />
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Button">
                <Grid x:Name="RootGrid">
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualState x:Name="Normal">
                                <Storyboard>
                                    <PointerUpThemeAnimation Storyboard.TargetName="RootGrid" />
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="PointerOver">
                                <VisualState.Setters>
                                    <Setter Target="RootGrid.(RevealBrush.State)"
                                            Value="PointerOver" />
                                    <Setter Target="BackgroundElement.Fill"
                                            Value="{ThemeResource ButtonRevealBackgroundPointerOver}" />
                                    <Setter Target="BackgroundElement.Stroke"
                                            Value="{ThemeResource ButtonRevealBorderBrushPointerOver}" />
                                    <Setter Target="ContentPresenter.Foreground"
                                            Value="{ThemeResource ButtonForegroundPointerOver}" />
                                </VisualState.Setters>
                                <Storyboard>
                                    <PointerUpThemeAnimation Storyboard.TargetName="RootGrid" />
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Pressed">
                                <VisualState.Setters>
                                    <Setter Target="RootGrid.(RevealBrush.State)"
                                            Value="Pressed" />
                                    <Setter Target="BackgroundElement.Fill"
                                            Value="{ThemeResource ButtonRevealBackgroundPressed}" />
                                    <Setter Target="BackgroundElement.Stroke"
                                            Value="{ThemeResource ButtonRevealBorderBrushPressed}" />
                                    <Setter Target="ContentPresenter.Foreground"
                                            Value="{ThemeResource ButtonForegroundPressed}" />
                                </VisualState.Setters>
                                <Storyboard>
                                    <PointerDownThemeAnimation Storyboard.TargetName="RootGrid" />
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Disabled">
                                <VisualState.Setters>
                                    <Setter Target="BackgroundElement.Fill"
                                            Value="{ThemeResource ButtonRevealBackgroundDisabled}" />
                                    <Setter Target="BackgroundElement.Stroke"
                                            Value="{ThemeResource ButtonRevealBorderBrushDisabled}" />
                                    <Setter Target="ContentPresenter.Foreground"
                                            Value="{ThemeResource ButtonForegroundDisabled}" />
                                </VisualState.Setters>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                    <Ellipse Stroke="{TemplateBinding BorderBrush}"
                             StrokeThickness="2"
                             Fill="Transparent"
                             x:Name="BackgroundElement" />
                    <ContentPresenter x:Name="ContentPresenter"
                                      Content="{TemplateBinding Content}"
                                      ContentTransitions="{TemplateBinding ContentTransitions}"
                                      ContentTemplate="{TemplateBinding ContentTemplate}"
                                      Padding="{TemplateBinding Padding}"
                                      HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                                      VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                                      AutomationProperties.AccessibilityView="Raw" />
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

这个样式实现了一个圆形的无边框按钮。看起来各种Reveal的Brush等资源都已高度封装好,不容易自定义。实际运行起来赏心悦目,这种效果,我很喜欢:

刚开始真的觉得这是程序员为了炫技而产生的效果,实际上配合Acrylic用起来整个不仅整个UI闪闪发光(很多人就是喜欢这个效果),而且提示可操作区域的解决方案中Reveal是目前我最满意的一个。像上面那个无边框按钮,它可以比幽灵按钮更进一步的简约,但鼠标接近时又可以清清楚楚提示哪些地方是可以操作的。

3. 注意事项

Reveal虽然很美好,用起来也很多讲究,重复一次以前提过的注意事项:

  • 只应该在可操作的元素上使用Reveal。
  • 不要在孤立的元素上使用Reveal。
  • 不要在大面积的元素上使用Reveal。
  • 静态元素(例如文字和背景)不应该使用Reveal。
  • 不应该让Reveal干扰重要的信息。

也就是说在List或一组按钮上使用才是正确用法。别一时兴起将SystemControlBackgroundAccentRevealBorderBrush之类的用在背景。

其它事项如Reveal没有生效及版本兼容性,可见之前的文章:如何使用Fluent Design System (下)

4. 结语

光照一直是设计师梦寐以求的元素,但不要因为可以用就去乱用,要适可而止(讲到我自己都觉得自己很婆婆妈妈了)。

5. 参考

Reveal highlight

6. 源码

Fluent Design System Sample

原文地址:https://www.cnblogs.com/dino623/p/Reveal.html

时间: 2024-08-01 02:10:40

[UWP]使用Reveal的相关文章

[UWP]如何使用Fluent Design System (下)

原文:[UWP]如何使用Fluent Design System (下) 4. 兼容旧版本 FDS最常见的问题之一是如何与Fall Creators Update之前的版本兼容,其实做起来也挺简单的,ColorfulBox就实现了Creators Update与Fall Creators Update之间的兼容. 4.1 使用HamburgerMenu代替NavigationView UWP Community Toolkit中的HamburgerMenu是以前制作汉堡包导航菜单最常用的方案,升

[UWP]如何使用Fluent Design System (上)

1. 前言 微软在Build 2017中公布了新的设计语言Fluent Design System(以下简称FDS),不过官网只是堆砌了各种华丽的词语以及一堆动画.至于在UWP中要做成怎么样,怎么做,可以参考这个视频: Build Amazing Apps with Fluent Design - Build 2017 视频中使用BuildCast这个示例应用详细展示了Fall Creators Update(16299)中如何实现FDS以及其它FCU的新API,极具参考价值. 或者参考开发人员

[UWP]从头开始创建并发布一个番茄钟

1. 自己用的番茄钟自己做 在PC上我一直使用"小番茄"作为我的番茄钟软件,我把它打开后放在副显示器最大化,这样不仅可以让它尽到本分,而且还可以告诉我的同事"我正在专心工作".可是我总是嫌弃它的手感不够愉悦,总想自己写一个番茄钟软件,正好最近很久没写UWP应用了很手痒,于是就抽空写了个自用的番茄钟并发布到微软应用商店. 结果手感也并不愉悦. 另外,本来本来我也打算用Storyboard实现动画,但火火总是劝我不要搞Storyboard,要用Composition A

Windows 10 UWP 部署

原文  http://youthlin.com/20151105.html 我们知道VS连接手机可以直接部署到手机里,但平板貌似无法这样干,平板与电脑连接没有丝毫反应……那么想看VS里写的uwp应用在平板上的运行情况怎么办呢? 如果是本机电脑的话,也可以直接调试,要是平板———— 当然是部署啦,不过怎么部署呢,网上搜到的有命令行 winappdeploycmd.exe 命令的,有Win8.1时代部署方法的,我用winappdeploycmd.exe试了一下,一直无法找到设备,连手机也搜不到,于是

Windows 10 UWP程序标题栏设置

原文:Windows 10 UWP程序标题栏设置 在Windows 10程序中,以前只能用于全屏方式的Metro程序现在可以运行在窗口模式下了,并且改了个新名字,叫Windows 通用程序(Universal Windows app),简称UWP程序.新的UWP程序虽然大体上还是和以前的Metro程序差不多的,但还是引入了一点新东西的,本文这里就介绍一下它的标题栏设置的几个特性. 隐藏标题栏: 将应用界面扩展至 Titlebar 区域 CoreApplication.GetCurrentView

设置UWP程序自启动(Automate launching Windows 10 UWP apps)

原文:设置UWP程序自启动(Automate launching Windows 10 UWP apps) 在开发UWP程序的过程中,有时候需要设置程序的自启.本人实现的步骤如下: 1.在VS中激活Protocol (Package.appxmanifest --> Declarations --> Add Protocol),图示如下: 2.编译并发布项目(Build and Deploy) 发布之后Protocol被激活,在(控制面板 --> 程序 --> 默认程序 -->

UWP开发之Mvvmlight实践九:基于MVVM的项目架构分享

在前几章介绍了不少MVVM以及Mvvmlight实例,那实际企业开发中将以那种架构开发比较好?怎样分层开发才能节省成本? 本文特别分享实际企业项目开发中使用过的项目架构,欢迎参照使用!有不好的地方欢迎指点! 基于MVVM的UWP项目架构 每个项目或者目录下需要什么文件如下图所示: 项目参照关系: 备注:如果使用Entity Framework Core做ORM持久层,只需要将UA.DataAccess层做替换就可以.希望本文能对您的团队开发带来一定功效.

UWP开发之Mvvmlight实践四:{x:bind}和{Binding}区别详解

{x:bind}是随着UWP被推出而被添加的,可以说是Win10 UWP开发专有扩展.虽然 {x:Bind} 缺少{Binding} 中的一些功能,但它运行时所花费的时间和使用的内存量均比 {Binding} 要少,且支持更好的调试. 参照网址:{x:Bind} 标记扩展,GitHub微软UWP实例之XamlBind 1,{x:Bind} 基本原理 在 XAML 加载时,{x:Bind} 将转换为你所需的绑定对象,此对象将从数据源上的某一属性中获取相关值.绑定对象可以配置为观察数据源属性值的更改

UWP开篇

我从WP8开始就在用Lumia手机,一路用到现在的WM10,电脑也早就参加Windows Insider用上了预览版. 最近WM10的负面消息很多,而主要的原因就是缺乏应用,缺少应用,这样就形成了一个循环,不仅各大厂商不愿意开发就连许多独立开发者也纷纷离开了,用户也减少了很多,看到这些难免也有些伤感. 我个人很喜欢Windows10这个平台,有时候自己想要的应用都没有, 尼玛年会抽奖微信居然还不能登陆微信抽奖的公众号!!! 尼玛年会抽奖微信居然还不能登陆微信抽奖的公众号!!! 尼玛年会抽奖微信居