RevealBackgroundBrush 中的显示高亮不起作用

Reveal highlight in RevealBackgroundBrush doesn't work

我尝试使用 RevealBackgroundBrush,但 Reveal Highlight 不起作用。

RevealBorderBrush 高光正常。

SDK 样式的 RevealBackgroundBrush 也可以工作(例如 "ButtonRevealStyle"),但是如果我在应用程序资源中复制 ButtonRevealStyle 并为按钮 RevealBackgroundBrush 应用样式则不起作用。

我重新安装了 windows,并尝试在另一个 uwp 项目中使用画笔,但是没有用

我尝试使用 CSharp 代码:

private void RevealGrid_Loaded(object sender, RoutedEventArgs e)
{
  var grid = sender as Grid;
  grid.Background = new RevealBackgroundBrush() {
    Color = Color.FromArgb(80, 0, 0, 0),
    TargetTheme = ApplicationTheme.Light,
    AlwaysUseFallback = false
  }; // grid.background
}

我尝试使用 Xaml:

<Grid Height="48" VerticalAlignment="Top" Loaded="RevealGrid_Loaded" >
   <Grid.Background>
      <RevealBackgroundBrush AlwaysUseFallback="False" TargetTheme="Light" Color="#33818181" />
   </Grid.Background>
</Grid>

详情:

RevealBackgroundBrush是动态效果,不是独立存在的。换句话说,RevealBackgroundBrush 取决于 state.

简单的 Grid 没有状态,所以 RevealBackgroundBrush 不起作用,但是我们可以使用 Grid 作为有状态控件的模板容器,比如 Button:

<Button Content="Yo!">
    <Button.Template>
        <ControlTemplate TargetType="Button">
            <Grid x:Name="Root" Width="100" Height="100">
                <Grid.Background>
                    <RevealBackgroundBrush/>
                </Grid.Background>
                <VisualStateManager.VisualStateGroups>
                    <VisualStateGroup x:Name="CommonStates">
                        <VisualState x:Name="Normal" />
                        <VisualState x:Name="PointerOver">
                            <VisualState.Setters>
                                <Setter Target="Root.(RevealBrush.State)" Value="PointerOver"/>
                            </VisualState.Setters>
                        </VisualState>
                        <VisualState x:Name="PointerOverPressed">
                            <VisualState.Setters>
                                <Setter Target="Root.(RevealBrush.State)" Value="Pressed"/>
                            </VisualState.Setters>
                        </VisualState>
                        <VisualState x:Name="Pressed">
                            <VisualState.Setters>
                                <Setter Target="Root.(RevealBrush.State)" Value="Pressed"/>
                            </VisualState.Setters>
                        </VisualState>
                    </VisualStateGroup>
                    <VisualStateGroup x:Name="DisabledStates">
                        <VisualState x:Name="Enabled"/>
                        <VisualState x:Name="Disabled">
                            <VisualState.Setters>
                                <Setter Target="Root.RevealBorderThickness" Value="0"/>
                            </VisualState.Setters>
                        </VisualState>
                    </VisualStateGroup>
                </VisualStateManager.VisualStateGroups>
                <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
            </Grid>
        </ControlTemplate>
    </Button.Template>

</Button>

我们使用VisualStateManager进行状态管理,调整Reveal的状态。

同样的道理也适用于其他控件。

此致。