为 WPF 应用程序使用加载指示器

Using a Loading Indicator for WPF application

我对 WPF 比较陌生,我想添加一个加载指示器。我发现 https://github.com/100GPing100/LoadingIndicators.WPF 有一些很好的预制加载指示器,我为它安装了 NuGet 包,但我很难将它们实现到我的 window.

所以我添加了

<Window ...
    xmlns:loadin="clr-namespace:LoadingIndicators.WPF;assembly=LoadingIndicators.WPF"
    ...
>

Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/LoadingIndicators.WPF;component/Styles/LoadingDoubleBounce.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Window.Resources>

但是当我尝试将其中一个加载指示器添加到我的网格时,我在动态资源上遇到错误

<Grid x:Name="TagLoadingIndicator" Panel.ZIndex="1">
    <loadin:LoadingIndicator SpeedRatio="{Binding SpeedRatio}" IsActive="{Binding IsDoubleBounceActive}" Style="{DynamicResource LoadingIndicatorDoubleBounceStyle}"/>
</Grid>

我得到的错误是

The resource "LoadingIndicatorDoubleBounceStyle" could not be resolved.

根据我在其他网站上看到的内容,我将其正确添加到 ResourceDictionary 中...并且我假设通过安装 NuGet 包,我已经定义了资源。我仍然可以 运行 该应用程序,但缺少指示器。我错过了什么?

谢谢

该密钥存在于 Styles.xaml 文件中。所以在你的资源中添加对它的引用。

<Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/LoadingIndicators.WPF;component/Styles/LoadingDoubleBounce.xaml"/>
            <ResourceDictionary Source="pack://application:,,,/LoadingIndicators.WPF;component/Styles.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
 </Window.Resources>