[UWP]使用Reveal

简介: 原文:[UWP]使用Reveal1. 前言 之前在 如何使用Fluent Design System 这篇文章里已经简单介绍过Reveal的用法,这篇再详细介绍其它内容。 2. 自定义RevealButtonStyle 我觉得常用ItemsControl都已经自动应用了Reveal,用就是了。
原文: [UWP]使用Reveal

1. 前言

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

2. 自定义RevealButtonStyle

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

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

只需简单地应用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等资源都已高度封装好,不容易自定义。实际运行起来赏心悦目,这种效果,我很喜欢:
img_061eeac8242e6c566fcd8c61089030b2.gif

刚开始真的觉得这是程序员为了炫技而产生的效果,实际上配合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

目录
相关文章
|
前端开发 Windows 数据可视化
[UWP]使用Popup构建UWP Picker
原文:[UWP]使用Popup构建UWP Picker 在上一篇博文《[UWP]不那么好用的ContentDialog》中我们讲到了ContentDialog在复杂场景下使用的几个令人头疼的弊端。那么,就让我们在这篇博文里开始愉快的造轮子之旅吧! 首先要向大家说明:这篇博文主要还是写的构建Picker时的思考过程,如果不感兴趣的,可以直接略过这篇,阅读下一篇《[UWP]如何使用Picker实现一个简单的ColorPicker弹窗》。
1001 0
|
Windows
UWP Acrylic Material
原文:UWP Acrylic Material 文档:https://docs.microsoft.com/en-us/windows/uwp/design/style/acrylic Acrylic 能带来类似 win7 的毛玻璃效果 要使用 Acrylic ,需要 win10 的版本最低为 ...
1014 0
|
Windows
Customize Acrylic Brush in UWP Applications(在UWP中自定义亚克力笔刷)
原文 Customize Acrylic Brush in UWP Applications(在UWP中自定义亚克力笔刷) Windows 10 Fall Creators Update(Build 16299)添加了acrylic brush,这是一个类似于Windows 7 Aero效果的UI画笔。
1408 0
|
Go C#
WPF Navigation
原文:WPF Navigation 在开始学习WPF时,一开始对WPF的Window, Page, UserControl感到很迷惑。不知道什么时候该使用哪一个。下面简单介绍一下这三者的区别。 Window:故名思意,桌面程序的窗体。
1478 0
|
C# 开发者
[UWP]新控件ColorPicker
原文:[UWP]新控件ColorPicker 1. 前言 Fall Creators Update中提供了一个新得ColorPicker控件,解决了以前选择颜色只能用Combo Box的窘境。 2. 一个简单的例子 如上所示,ColorPiker可以通过在光谱或色轮上拖动滑块,或者在RGB/HSV及十六进制的TextBox中直接输入颜色的数值改变Color属性。
1027 0
|
C# 程序员
[UWP]做个调皮的BusyIndicator
原文:[UWP]做个调皮的BusyIndicator 1. 前言 最近突然想要个BusyIndicator。做过WPF开发的程序员对BusyIndicator应该不陌生,Extended WPF Toolkit 提供了BusyIndicator的开源实现,Silverlight Toolkit也有一个,这次想要把这个控件移植到UWP中。
913 0
[UWP]使用Acrylic(亚克力)
原文:[UWP]使用Acrylic(亚克力) 1. 前言 在 如何使用Fluent Design System 这篇文章里已经简单介绍过Reveal的用法,这篇再详细介绍其它内容。 自Windows 8 放弃Aero后,群众对毛玻璃回归的呼声一致都很大。
1504 0
|
JavaScript C#
wpf CefSharp 与 js交互
原文:wpf CefSharp 与 js交互 通过 NuGet 获取 CefSharp.WpF 组件。  xmlns:cefSharp="clr-namespace:CefSharp.
3857 0
|
搜索推荐 API 开发者
简单说一下UWP中的JumpList
原文:简单说一下UWP中的JumpList   在Windows10的10856这个版本中,微软为桌面版提供了一组新的应用交互方式,磁贴和Toast通知的个性化都有了一定的改善。针对磁贴方面,微软为我们提供了一组新的API来扩充我们对应用的交互方式——JumpList。
805 0
|
C# Shell 缓存
从PRISM开始学WPF(八)导航Navigation?
原文:从PRISM开始学WPF(八)导航Navigation? 0x6Navigation Basic Navigation Prism中的Navigation提供了一种类似导航的功能,他可以根据用户的输入,来刷新UI。
1437 0