【问题标题】:Unable to change the background colour of TeachingTip in UWP无法在 UWP 中更改 TeachingTip 的背景颜色
【发布时间】:2020-07-03 12:22:51
【问题描述】:

我在UWP中使用WinUi 2.4的教学提示控件,想改变背景颜色。但是我在 xaml 中给出的背景值并没有反映在控制中。

 <winui:TeachingTip x:Name="ToggleThemeTeachingTip2"
  Title="Change themes without hassle"
  Subtitle="It's easier than ever to see control samples in both light and dark theme!"
  PreferredPlacement="Auto"
PlacementMargin="20"                    
IsLightDismissEnabled="True"
  Background="Red"
   >
  • 这里我将背景值设置为红色,但它没有反映在控件中。我认为它只采用默认值,有没有办法覆盖默认值并设置我们的值,如背景颜色。
  • 在这个例子中看到了一些建议,但它不起作用 Changing default values of tooltipDefaultValues

【问题讨论】:

    标签: xaml uwp winui


    【解决方案1】:

    这不是很好笑吗?因为当您将 light dismiss 设置为 false 时它会起作用。

    原因在这里:https://github.com/microsoft/microsoft-ui-xaml/blob/master/dev/TeachingTip/TeachingTip.xaml#L32

    看到在LightDismiss 状态它强制主题值。

    因此您需要复制和编辑该样式以尊重 TemplateBinding(您在控件上设置的红色)

    <VisualState x:Name="LightDismiss">
        <VisualState.Setters>
            <Setter Target="TailEdgeBorder.Background" Value="{Binding Background,RelativeSource={RelativeSource TemplatedParent}}"/>
            <Setter Target="TailPolygon.Fill" Value="{Binding Background,RelativeSource={RelativeSource TemplatedParent}}"/>
            <Setter Target="TopTailPolygonHighlight.Fill" Value="{Binding Background,RelativeSource={RelativeSource TemplatedParent}}"/>
            <Setter Target="ContentRootGrid.Background" Value="{Binding Background,RelativeSource={RelativeSource TemplatedParent}}"/>
        </VisualState.Setters>
    </VisualState>
    
    

    我让您更轻松地共享完整的 App.xaml 文件以及一些命名空间编辑等:

    https://pastebin.com/QgPpqMKS

    只需更改 x:class,我的是 App9。另请注意,我用 CornerRadius 注释了该行,因为它会引发一些错误 (??)。

    还可以为您的教学提示添加风格:

     <winui:TeachingTip x:Name="ToggleThemeTeachingTip2"
      Title="Change themes without hassle"
      Subtitle="It's easier than ever to see control samples in both light and dark theme!"
      PreferredPlacement="Auto"
    PlacementMargin="20"                    
    IsLightDismissEnabled="True"
    Style="{StaticResource MyTeachingTipStyle}"
      Background="Red"
       >
    

    【讨论】:

      猜你喜欢
      • 2016-07-04
      • 2020-09-15
      • 2013-03-14
      • 2016-10-04
      • 2014-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多