0

我知道使用Uno 尚不支持的模板绑定方式全局修改主题颜色。(我为 ToggleSwitch 尝试过,现在 ToggleSwitch 自定义样式在 UWP 和 WASM 上都能完美运行)。所以,我以同样的方式为 WinUI 2.4 ProgressRing 准备了一个自定义样式。我从 WinUI Github repo 收集了 ProgressRing 的默认样式并对其进行了自定义:

 <!-- Default style for Microsoft.UI.Xaml.Controls.ProgressRing -->
            <Style x:Key="AcmProgressRing" TargetType="controls:ProgressRing">
                <Setter Property="Foreground" Value="{StaticResource AcmPink}" />
                <Setter Property="Background" Value="{StaticResource AcmPurple}" />
                <Setter Property="IsHitTestVisible" Value="False" />
                <Setter Property="HorizontalAlignment" Value="Center" />
                <Setter Property="VerticalAlignment" Value="Center" />
                <Setter Property="MinHeight" Value="16" />
                <Setter Property="MinWidth" Value="16" />
                <Setter Property="IsTabStop" Value="False" />
                <Setter Property="Width" Value="32" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="controls:ProgressRing">
                            <Grid x:Name="LayoutRoot" Background="Transparent">
                                <VisualStateManager.VisualStateGroups>
                                    <VisualStateGroup x:Name="CommonStates">
                                        <VisualState x:Name="Active">
                                            <Storyboard>
                                                <DoubleAnimation
                                            Storyboard.TargetName="LayoutRoot"
                                            Storyboard.TargetProperty="Opacity"
                                            To="1"
                                            Duration="0:0:0.15" />
                                            </Storyboard>
                                        </VisualState>
                                        <VisualState x:Name="Inactive">
                                            <Storyboard>
                                                <DoubleAnimation
                                            Storyboard.TargetName="LayoutRoot"
                                            Storyboard.TargetProperty="Opacity"
                                            To="0"
                                            Duration="0" />
                                            </Storyboard>
                                        </VisualState>
                                    </VisualStateGroup>
                                </VisualStateManager.VisualStateGroups>
                                <!-- AnimatedVisualPlayer for Lottie -->
                                <controls:AnimatedVisualPlayer x:Name="IndeterminateAnimatedVisualPlayer" AutoPlay="false" Stretch="fill"/>

                            </Grid>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

我的 ProgressRing 是:

<controls:ProgressRing x:Name="Waiter" Width="50" Height="50" Style="{StaticResource AcmProgressRing}" IsActive="True"/>

如您所见,该样式在 UWP 上正确运行: 在此处输入图像描述

但是,WASM 显示默认样式:(

在此处输入图像描述

套餐

  - Uno.UI.RemoteControl {2.4.0}

  - Newtonsoft.Json {12.0.3}

  - Uno.UI.Lottie {2.4.0}

  - Uno.Wasm.Bootstrap {1.2.0}

  - Uno.Wasm.Bootstrap.DevServer {1.2.0}

  - ACM_Search_AdminApps.Shared {1.1.0}

  - Microsoft.Extensions.Logging.Filter {1.1.2}

  - Microsoft.Extensions.Logging.Con... {1.1.1}

  - NETStandard.Library {2.0.3}

   - Uno.UI {2.4.0}

   - ACM_Search_AdminApps.Shared {1.1.0}

  - Microsoft.NETCore.UniversalWindo... {6.2.10}

   - Microsoft.Extensions.Logging.Con... {1.1.1}

  - Microsoft.Extensions.Logging.Filter {1.1.2}

  - Microsoft.Toolkit.Uwp.UI.Lottie {6.0.0}

  - Microsoft.UI.Xaml {2.4.2}

   - Newtonsoft.Json {12.0.3}

  - Uno.Core {2.0.0}

WASM 上 WinUI ProgressRing 的样式必须与 UWP 样式匹配。我怎样才能解决这个问题 ?谢谢。

4

0 回答 0