【问题标题】:Reveal highlight in RevealBackgroundBrush doesn't workRevealBackgroundBrush 中的显示突出显示不起作用
【发布时间】:2019-12-08 16:43:21
【问题描述】:

我尝试使用 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>

详情:

  • Visual Studio 2019

  • SDK 10.0.18362.0

  • Windows 10 专业版 1903(18362.239 内部版本)

【问题讨论】:

    标签: c# xaml uwp uwp-xaml uwp-c#


    【解决方案1】:

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

    简单的 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的状态。

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

    最好的问候。

    【讨论】:

    • 如何以编程方式执行此操作?
    猜你喜欢
    • 1970-01-01
    • 2016-01-16
    • 1970-01-01
    • 1970-01-01
    • 2016-05-13
    • 2016-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多